import React, { useState, useEffect, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { reportService, categoryService } from '../services/api';
import useFormatters from '../hooks/useFormatters';
import BalanceProjectionChart from '../components/dashboard/BalanceProjectionChart';
import {
  Chart as ChartJS,
  CategoryScale,
  LinearScale,
  BarElement,
  LineElement,
  PointElement,
  ArcElement,
  Title,
  Tooltip,
  Legend,
  Filler,
} from 'chart.js';
import { Bar, Line, Doughnut, Pie } from 'react-chartjs-2';

ChartJS.register(
  CategoryScale,
  LinearScale,
  BarElement,
  LineElement,
  PointElement,
  ArcElement,
  Title,
  Tooltip,
  Legend,
  Filler
);

const Reports = () => {
  const { t } = useTranslation();
  const { currency, date: formatDate } = useFormatters();
  
  // Mobile detection
  const [isMobile, setIsMobile] = useState(window.innerWidth < 768);

  useEffect(() => {
    const handleResize = () => setIsMobile(window.innerWidth < 768);
    window.addEventListener('resize', handleResize);
    return () => window.removeEventListener('resize', handleResize);
  }, []);
  
  const [activeTab, setActiveTab] = useState('summary');
  const [loading, setLoading] = useState(true);
  const [year, setYear] = useState(new Date().getFullYear());
  const [months, setMonths] = useState(12);
  
  // Data states
  const [summary, setSummary] = useState(null);
  const [categoryData, setCategoryData] = useState(null);
  const [selectedCategory, setSelectedCategory] = useState(null);
  const [evolutionData, setEvolutionData] = useState(null);
  const [dayOfWeekData, setDayOfWeekData] = useState(null);
  const [topExpenses, setTopExpenses] = useState(null);
  const [projection, setProjection] = useState(null);
  const [comparison, setComparison] = useState(null);
  const [costCenterData, setCostCenterData] = useState(null);
  const [recurringData, setRecurringData] = useState(null);
  const [liabilitiesData, setLiabilitiesData] = useState(null);
  const [futureData, setFutureData] = useState(null);
  const [overdueData, setOverdueData] = useState(null);

  // Load data based on active tab
  const loadData = useCallback(async () => {
    setLoading(true);
    try {
      switch (activeTab) {
        case 'summary':
          const summaryRes = await reportService.getSummary({ year });
          setSummary(summaryRes);
          break;
        case 'category':
          const params = { type: 'debit' };
          if (selectedCategory) {
            params.parent_id = selectedCategory.category_id;
          }
          const catRes = await reportService.getByCategory(params);
          setCategoryData(catRes);
          break;
        case 'evolution':
          const evoRes = await reportService.getMonthlyEvolution({ months });
          setEvolutionData(evoRes);
          break;
        case 'dayOfWeek':
          const dowRes = await reportService.getByDayOfWeek({ months: 6 });
          setDayOfWeekData(dowRes);
          break;
        case 'topExpenses':
          const topRes = await reportService.getTopExpenses({ limit: 20 });
          setTopExpenses(topRes);
          break;
        case 'projection':
          const projRes = await reportService.getProjection();
          setProjection(projRes);
          break;
        case 'comparison':
          const compRes = await reportService.comparePeriods();
          setComparison(compRes);
          break;
        case 'costCenter':
          const ccRes = await reportService.getByCostCenter();
          setCostCenterData(ccRes);
          break;
        case 'recurring':
          const recRes = await reportService.getRecurringReport();
          setRecurringData(recRes);
          break;
        case 'liabilities':
          const liabRes = await reportService.getLiabilities();
          setLiabilitiesData(liabRes);
          break;
        case 'future':
          const futRes = await reportService.getFutureTransactions({ days: 30 });
          setFutureData(futRes);
          break;
        case 'overdue':
          const overdueRes = await reportService.getOverdue();
          setOverdueData(overdueRes);
          break;
      }
    } catch (error) {
      console.error('Error loading report data:', error);
    } finally {
      setLoading(false);
    }
  }, [activeTab, year, months]);

  useEffect(() => {
    loadData();
  }, [loadData]);

  const tabs = [
    { id: 'summary', label: t('reports.summary'), icon: 'bi-clipboard-data' },
    { id: 'category', label: t('reports.byCategory'), icon: 'bi-pie-chart' },
    { id: 'costCenter', label: t('reports.byCostCenter'), icon: 'bi-diagram-3' },
    { id: 'evolution', label: t('reports.monthlyEvolution'), icon: 'bi-graph-up' },
    { id: 'comparison', label: t('reports.comparison'), icon: 'bi-arrow-left-right' },
    { id: 'topExpenses', label: t('reports.topExpenses'), icon: 'bi-sort-down' },
    { id: 'projection', label: t('reports.projection'), icon: 'bi-lightning' },
    { id: 'recurring', label: t('reports.recurring'), icon: 'bi-arrow-repeat' },
    { id: 'liabilities', label: t('reports.liabilities'), icon: 'bi-credit-card' },
    { id: 'future', label: t('reports.futureTransactions'), icon: 'bi-calendar-plus' },
    { id: 'overdue', label: t('reports.overdue'), icon: 'bi-exclamation-triangle' },
  ];

  // Chart options
  const chartOptions = {
    responsive: true,
    maintainAspectRatio: false,
    plugins: {
      legend: {
        labels: { color: '#94a3b8' }
      }
    },
    scales: {
      x: {
        ticks: { color: '#94a3b8' },
        grid: { color: 'rgba(148, 163, 184, 0.1)' }
      },
      y: {
        ticks: { color: '#94a3b8' },
        grid: { color: 'rgba(148, 163, 184, 0.1)' }
      }
    }
  };

  const doughnutOptions = {
    responsive: true,
    maintainAspectRatio: false,
    plugins: {
      legend: {
        position: 'right',
        labels: { color: '#94a3b8', padding: 15, font: { size: 11 } }
      }
    }
  };

  // Render Summary Tab
  const renderSummary = () => {
    if (!summary) return null;

    const savingsRate = summary.current.income > 0 
      ? ((summary.current.balance / summary.current.income) * 100).toFixed(1) 
      : 0;
    
    const monthlyAvgIncome = (summary.current.income / 12).toFixed(2);
    const monthlyAvgExpense = (summary.current.expense / 12).toFixed(2);
    const monthlyAvgBalance = (summary.current.balance / 12).toFixed(2);

    return (
      <div className="row g-3">
        {/* Year Selector */}
        <div className="col-12">
          <div className="d-flex align-items-center justify-content-between mb-3">
            <h5 className="text-white mb-0" style={{ fontSize: isMobile ? '0.95rem' : '1.25rem' }}>
              <i className="bi bi-calendar3 me-2"></i>
              {t('reports.annualSummary')}
            </h5>
            <div className="btn-group" role="group">
              {[2024, 2025].map(y => (
                <button
                  key={y}
                  className={`btn ${year === y ? 'btn-primary' : 'btn-outline-secondary'}`}
                  onClick={() => setYear(y)}
                  style={{ 
                    fontSize: isMobile ? '0.75rem' : '0.875rem',
                    padding: isMobile ? '0.25rem 0.75rem' : '0.375rem 1rem'
                  }}
                >
                  {y}
                </button>
              ))}
            </div>
          </div>
        </div>

        {/* Main KPI Cards */}
        <div className={isMobile ? "col-12" : "col-lg-3 col-md-6"}>
          <div className="card border-0 h-100" style={{ background: 'linear-gradient(135deg, #059669 0%, #047857 100%)' }}>
            <div className="card-body text-white" style={{ padding: isMobile ? '0.75rem' : '1rem' }}>
              <div className="d-flex align-items-center justify-content-between mb-2">
                <div style={{ minWidth: 0, flex: 1 }}>
                  <div className="opacity-75 text-uppercase fw-semibold mb-1" style={{ fontSize: isMobile ? '0.65rem' : '0.75rem' }}>
                    {t('reports.income')}
                  </div>
                  <h3 className="mb-0 fw-bold" style={{ fontSize: isMobile ? '1.1rem' : '1.5rem' }}>
                    {currency(summary.current.income, summary.currency)}
                  </h3>
                </div>
                {!isMobile && (
                  <div className="fs-1 opacity-50">
                    <i className="bi bi-arrow-up-circle"></i>
                  </div>
                )}
              </div>
              {summary.variation.income !== 0 && !isNaN(summary.variation.income) && isFinite(summary.variation.income) && (
                <div className="d-flex align-items-center gap-2">
                  <span className={`badge ${summary.variation.income >= 0 ? 'bg-white text-success' : 'bg-white text-danger'}`}
                        style={{ fontSize: isMobile ? '0.65rem' : '0.75rem', padding: isMobile ? '0.25rem 0.5rem' : '0.375rem 0.75rem' }}>
                    <i className={`bi bi-arrow-${summary.variation.income >= 0 ? 'up' : 'down'} me-1`}></i>
                    {Math.abs(summary.variation.income).toFixed(1)}%
                  </span>
                  <small className="opacity-75" style={{ fontSize: isMobile ? '0.65rem' : '0.75rem' }}>
                    {t('reports.vsLastYear')}
                  </small>
                </div>
              )}
              <hr className="my-2 opacity-25" />
              <div className="d-flex justify-content-between" style={{ fontSize: isMobile ? '0.7rem' : '0.875rem' }}>
                <span className="opacity-75">{t('reports.monthlyAverage')}:</span>
                <span className="fw-semibold">{currency(monthlyAvgIncome, summary.currency)}</span>
              </div>
            </div>
          </div>
        </div>

        <div className={isMobile ? "col-12" : "col-lg-3 col-md-6"}>
          <div className="card border-0 h-100" style={{ background: 'linear-gradient(135deg, #dc2626 0%, #b91c1c 100%)' }}>
            <div className="card-body text-white" style={{ padding: isMobile ? '0.75rem' : '1rem' }}>
              <div className="d-flex align-items-center justify-content-between mb-2">
                <div style={{ minWidth: 0, flex: 1 }}>
                  <div className="opacity-75 text-uppercase fw-semibold mb-1" style={{ fontSize: isMobile ? '0.65rem' : '0.75rem' }}>
                    {t('reports.expenses')}
                  </div>
                  <h3 className="mb-0 fw-bold" style={{ fontSize: isMobile ? '1.1rem' : '1.5rem' }}>
                    {currency(summary.current.expense, summary.currency)}
                  </h3>
                </div>
                {!isMobile && (
                  <div className="fs-1 opacity-50">
                    <i className="bi bi-arrow-down-circle"></i>
                  </div>
                )}
              </div>
              {summary.variation.expense !== 0 && !isNaN(summary.variation.expense) && isFinite(summary.variation.expense) && (
                <div className="d-flex align-items-center gap-2">
                  <span className={`badge ${summary.variation.expense <= 0 ? 'bg-white text-success' : 'bg-white text-danger'}`}
                        style={{ fontSize: isMobile ? '0.65rem' : '0.75rem', padding: isMobile ? '0.25rem 0.5rem' : '0.375rem 0.75rem' }}>
                    <i className={`bi bi-arrow-${summary.variation.expense >= 0 ? 'up' : 'down'} me-1`}></i>
                    {Math.abs(summary.variation.expense).toFixed(1)}%
                  </span>
                  <small className="opacity-75" style={{ fontSize: isMobile ? '0.65rem' : '0.75rem' }}>
                    {t('reports.vsLastYear')}
                  </small>
                </div>
              )}
              <hr className="my-2 opacity-25" />
              <div className="d-flex justify-content-between" style={{ fontSize: isMobile ? '0.7rem' : '0.875rem' }}>
                <span className="opacity-75">{t('reports.monthlyAverage')}:</span>
                <span className="fw-semibold">{currency(monthlyAvgExpense, summary.currency)}</span>
              </div>
            </div>
          </div>
        </div>

        <div className={isMobile ? "col-12" : "col-lg-3 col-md-6"}>
          <div className="card border-0 h-100" style={{ background: 'linear-gradient(135deg, #3b82f6 0%, #2563eb 100%)' }}>
            <div className="card-body text-white" style={{ padding: isMobile ? '0.75rem' : '1rem' }}>
              <div className="d-flex align-items-center justify-content-between mb-2">
                <div style={{ minWidth: 0, flex: 1 }}>
                  <div className="opacity-75 text-uppercase fw-semibold mb-1" style={{ fontSize: isMobile ? '0.65rem' : '0.75rem' }}>
                    {t('reports.balance')}
                  </div>
                  <h3 className="mb-0 fw-bold" style={{ fontSize: isMobile ? '1.1rem' : '1.5rem' }}>
                    {currency(summary.current.balance, summary.currency)}
                  </h3>
                </div>
                {!isMobile && (
                  <div className="fs-1 opacity-50">
                    <i className="bi bi-wallet2"></i>
                  </div>
                )}
              </div>
              {summary.variation.balance !== 0 && !isNaN(summary.variation.balance) && isFinite(summary.variation.balance) && (
                <div className="d-flex align-items-center gap-2">
                  <span className={`badge ${summary.variation.balance >= 0 ? 'bg-white text-success' : 'bg-white text-danger'}`}
                        style={{ fontSize: isMobile ? '0.65rem' : '0.75rem', padding: isMobile ? '0.25rem 0.5rem' : '0.375rem 0.75rem' }}>
                    <i className={`bi bi-arrow-${summary.variation.balance >= 0 ? 'up' : 'down'} me-1`}></i>
                    {Math.abs(summary.variation.balance).toFixed(1)}%
                  </span>
                  <small className="opacity-75" style={{ fontSize: isMobile ? '0.65rem' : '0.75rem' }}>
                    {t('reports.vsLastYear')}
                  </small>
                </div>
              )}
              <hr className="my-2 opacity-25" />
              <div className="d-flex justify-content-between" style={{ fontSize: isMobile ? '0.7rem' : '0.875rem' }}>
                <span className="opacity-75">{t('reports.monthlyAverage')}:</span>
                <span className="fw-semibold">{currency(monthlyAvgBalance, summary.currency)}</span>
              </div>
            </div>
          </div>
        </div>

        <div className="col-lg-3 col-md-6">
          <div className="card border-0 h-100" style={{ background: 'linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)' }}>
            <div className="card-body text-white">
              <div className="d-flex align-items-center justify-content-between mb-3">
                <div>
                  <div className="opacity-75 small text-uppercase fw-semibold mb-1">{t('reports.savingsRate')}</div>
                  <h3 className="mb-0 fw-bold">{savingsRate}%</h3>
                </div>
                <div className="fs-1 opacity-50">
                  <i className="bi bi-piggy-bank"></i>
                </div>
              </div>
              <div className="progress mb-2" style={{ height: '8px', background: 'rgba(255,255,255,0.2)' }}>
                <div 
                  className="progress-bar bg-white" 
                  role="progressbar" 
                  style={{ width: `${Math.min(savingsRate, 100)}%` }}
                ></div>
              </div>
              <small className="opacity-75">
                {savingsRate >= 20 ? '🎯 ' + t('reports.excellentSavings') :
                 savingsRate >= 10 ? '👍 ' + t('reports.goodSavings') :
                 '💡 ' + t('reports.canImprove')}
              </small>
            </div>
          </div>
        </div>

        {/* Comparison Chart */}
        <div className="col-12">
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className="card-header border-0 bg-transparent">
              <div className="d-flex align-items-center justify-content-between">
                <h6 className="text-white mb-0">
                  <i className="bi bi-bar-chart-line me-2"></i>
                  {t('reports.yearComparison')} - {year-1} vs {year}
                </h6>
                <span className="badge bg-primary">
                  {t('reports.total')}: {currency(summary.current.balance, summary.currency)}
                </span>
              </div>
            </div>
            <div className="card-body" style={{ height: '320px' }}>
              <Bar
                data={{
                  labels: [t('common.incomes'), t('common.expenses'), t('common.balance')],
                  datasets: [
                    {
                      label: String(year - 1),
                      data: [summary.previous.income, summary.previous.expense, summary.previous.balance],
                      backgroundColor: 'rgba(100, 116, 139, 0.6)',
                      borderColor: '#64748b',
                      borderWidth: 2,
                      borderRadius: 6,
                    },
                    {
                      label: String(year),
                      data: [summary.current.income, summary.current.expense, summary.current.balance],
                      backgroundColor: ['rgba(16, 185, 129, 0.8)', 'rgba(239, 68, 68, 0.8)', 'rgba(59, 130, 246, 0.8)'],
                      borderColor: ['#10b981', '#ef4444', '#3b82f6'],
                      borderWidth: 2,
                      borderRadius: 6,
                    },
                  ],
                }}
                options={{
                  ...chartOptions,
                  plugins: {
                    ...chartOptions.plugins,
                    legend: {
                      position: 'top',
                      labels: { 
                        color: '#94a3b8',
                        padding: 15,
                        font: { size: 12, weight: 'bold' }
                      }
                    },
                    tooltip: {
                      backgroundColor: 'rgba(15, 23, 42, 0.95)',
                      titleColor: '#fff',
                      bodyColor: '#94a3b8',
                      borderColor: '#334155',
                      borderWidth: 1,
                      padding: 12,
                      displayColors: true,
                      callbacks: {
                        label: function(context) {
                          return `${context.dataset.label}: ${currency(context.parsed.y, summary.currency)}`;
                        }
                      }
                    }
                  }
                }}
              />
            </div>
          </div>
        </div>
      </div>
    );
  };

  // Render Category Tab
  const renderCategory = () => {
    if (!categoryData) return null;

    const colors = categoryData.data.map((_, i) => 
      `hsl(${(i * 360) / categoryData.data.length}, 70%, 50%)`
    );

    const handleCategoryClick = (cat) => {
      setSelectedCategory(cat);
      loadData();
    };

    const handleBackToCategories = () => {
      setSelectedCategory(null);
      loadData();
    };

    return (
      <div className="row g-4">
        {/* Botão Voltar */}
        {selectedCategory && (
          <div className="col-12">
            <button 
              className="btn btn-sm btn-outline-secondary"
              onClick={handleBackToCategories}
            >
              <i className="bi bi-arrow-left me-2"></i>
              {t('common.back')} - {selectedCategory.category_name}
            </button>
          </div>
        )}
        {/* Gráfico de Distribuição */}
        <div className={isMobile ? 'col-12' : 'col-lg-6'}>
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className={`card-header border-0 bg-transparent ${isMobile ? 'p-2' : ''}`}>
              <h6 className="text-white mb-0" style={{ fontSize: isMobile ? '0.85rem' : '1rem' }}>
                <i className="bi bi-pie-chart me-2"></i>
                {selectedCategory ? t('reports.subcategoryDistribution') : t('reports.expenseDistribution')}
              </h6>
            </div>
            <div className={isMobile ? 'p-2' : 'card-body'} style={{ height: isMobile ? '300px' : '400px' }}>
              <Doughnut
                data={{
                  labels: categoryData.data.map(c => c.category_name),
                  datasets: [{
                    data: categoryData.data.map(c => c.total),
                    backgroundColor: colors,
                    borderWidth: 0,
                  }],
                }}
                options={{
                  ...doughnutOptions,
                  onClick: !selectedCategory ? (event, elements) => {
                    if (elements.length > 0) {
                      const index = elements[0].index;
                      const cat = categoryData.data[index];
                      handleCategoryClick(cat);
                    }
                  } : undefined
                }}
              />
            </div>
          </div>
        </div>

        {/* Tabela/Lista de Detalhes */}
        <div className={isMobile ? 'col-12' : 'col-lg-6'}>
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className={`card-header border-0 bg-transparent d-flex justify-content-between ${isMobile ? 'p-2' : ''}`}>
              <h6 className="text-white mb-0" style={{ fontSize: isMobile ? '0.85rem' : '1rem' }}>
                <i className="bi bi-list-ol me-2"></i>
                {t('reports.categoryDetail')}
              </h6>
              <span className="text-success fw-bold" style={{ fontSize: isMobile ? '0.85rem' : '1rem' }}>
                {currency(categoryData.total, categoryData.currency)}
              </span>
            </div>

            {/* Desktop: Tabela */}
            {!isMobile && (
              <div className="card-body p-0" style={{ maxHeight: '400px', overflowY: 'auto' }}>
                <table className="table table-dark table-hover mb-0">
                  <thead className="sticky-top" style={{ background: '#1e293b' }}>
                    <tr>
                      <th>{t('reports.category')}</th>
                      <th className="text-end">{t('common.total')}</th>
                      <th className="text-end">%</th>
                    </tr>
                  </thead>
                  <tbody>
                    {categoryData.data.map((cat, i) => (
                      <tr 
                        key={cat.category_id}
                        onClick={() => !selectedCategory && handleCategoryClick(cat)}
                        style={{ cursor: !selectedCategory ? 'pointer' : 'default' }}
                        className={!selectedCategory ? 'table-hover-row' : ''}
                      >
                        <td>
                          <i className={`bi ${cat.icon} me-2`} style={{ color: colors[i] }}></i>
                          {cat.category_name}
                        </td>
                        <td className="text-end">{currency(cat.total, categoryData.currency)}</td>
                        <td className="text-end">
                          <span className="badge bg-secondary">{cat.percentage}%</span>
                        </td>
                      </tr>
                    ))}
                  </tbody>
                </table>
              </div>
            )}

            {/* Mobile: Cards */}
            {isMobile && (
              <div className="p-2" style={{ maxHeight: '400px', overflowY: 'auto' }}>
                {categoryData.data.map((cat, i) => (
                  <div 
                    key={cat.category_id}
                    className="card mb-2 border-0"
                    style={{ background: '#1e293b', cursor: !selectedCategory ? 'pointer' : 'default' }}
                    onClick={() => !selectedCategory && handleCategoryClick(cat)}
                  >
                    <div className="card-body p-2">
                      <div className="d-flex justify-content-between align-items-start mb-1">
                        <div className="d-flex align-items-center gap-2">
                          <i className={`bi ${cat.icon}`} style={{ color: colors[i], fontSize: '1rem' }}></i>
                          <span className="text-white" style={{ fontSize: '0.85rem' }}>
                            {cat.category_name}
                          </span>
                        </div>
                        <span className="badge bg-secondary" style={{ fontSize: '0.7rem' }}>
                          {cat.percentage}%
                        </span>
                      </div>
                      <div className="text-end">
                        <span className="text-success fw-bold" style={{ fontSize: '0.9rem' }}>
                          {currency(cat.total, categoryData.currency)}
                        </span>
                      </div>
                    </div>
                  </div>
                ))}
              </div>
            )}
          </div>
        </div>
      </div>
    );
  };

  // Render Evolution Tab
  const renderEvolution = () => {
    if (!evolutionData) return null;

    return (
      <div className="row g-4">
        {/* Period Selector */}
        <div className="col-12">
          <div className={`d-flex gap-2 ${isMobile ? 'mb-2' : 'mb-3'}`}>
            {[6, 12, 24].map(m => (
              <button
                key={m}
                className={`btn ${isMobile ? 'btn-xs' : 'btn-sm'} ${months === m ? 'btn-primary' : 'btn-outline-secondary'}`}
                onClick={() => setMonths(m)}
                style={isMobile ? { fontSize: '0.75rem', padding: '0.25rem 0.5rem' } : {}}
              >
                {m} {t('common.months')}
              </button>
            ))}
          </div>
        </div>

        {/* Averages Cards */}
        <div className={isMobile ? 'col-6' : 'col-md-3'}>
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className={isMobile ? 'card-body p-2' : 'card-body'}>
              <small className="text-slate-400" style={{ fontSize: isMobile ? '0.7rem' : '0.875rem' }}>
                {t('reports.avgIncome')}
              </small>
              <h5 className="text-success mb-0" style={{ fontSize: isMobile ? '0.85rem' : '1.25rem' }}>
                {currency(evolutionData.averages.income, evolutionData.currency)}
              </h5>
            </div>
          </div>
        </div>
        <div className={isMobile ? 'col-6' : 'col-md-3'}>
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className={isMobile ? 'card-body p-2' : 'card-body'}>
              <small className="text-slate-400" style={{ fontSize: isMobile ? '0.7rem' : '0.875rem' }}>
                {t('reports.avgExpense')}
              </small>
              <h5 className="text-danger mb-0" style={{ fontSize: isMobile ? '0.85rem' : '1.25rem' }}>
                {currency(evolutionData.averages.expense, evolutionData.currency)}
              </h5>
            </div>
          </div>
        </div>
        <div className={isMobile ? 'col-6' : 'col-md-3'}>
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className={isMobile ? 'card-body p-2' : 'card-body'}>
              <small className="text-slate-400" style={{ fontSize: isMobile ? '0.7rem' : '0.875rem' }}>
                {t('reports.balance')}
              </small>
              <h5 className={`mb-0 ${evolutionData.averages.balance >= 0 ? 'text-success' : 'text-danger'}`} style={{ fontSize: isMobile ? '0.85rem' : '1.25rem' }}>
                {currency(evolutionData.averages.balance, evolutionData.currency)}
              </h5>
            </div>
          </div>
        </div>
        <div className={isMobile ? 'col-6' : 'col-md-3'}>
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className={isMobile ? 'card-body p-2' : 'card-body'}>
              <small className="text-slate-400" style={{ fontSize: isMobile ? '0.7rem' : '0.875rem' }}>
                {t('reports.savingsRate')}
              </small>
              <h5 className="text-primary mb-0" style={{ fontSize: isMobile ? '0.85rem' : '1.25rem' }}>
                {evolutionData.averages.savings_rate}%
              </h5>
            </div>
          </div>
        </div>

        {/* Evolution Chart */}
        <div className="col-12">
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className={`card-header border-0 bg-transparent ${isMobile ? 'p-2' : ''}`}>
              <h6 className="text-white mb-0" style={{ fontSize: isMobile ? '0.85rem' : '1rem' }}>
                <i className="bi bi-graph-up me-2"></i>
                {t('reports.monthlyEvolution')}
              </h6>
            </div>
            <div className={isMobile ? 'p-2' : 'card-body'} style={{ height: isMobile ? '250px' : '350px' }}>
              <Line
                data={{
                  labels: evolutionData.data.map(d => d.month_label),
                  datasets: [
                    {
                      label: t('reports.income'),
                      data: evolutionData.data.map(d => d.income),
                      borderColor: '#10b981',
                      backgroundColor: 'rgba(16, 185, 129, 0.1)',
                      fill: true,
                      tension: 0.3,
                    },
                    {
                      label: t('reports.expenses'),
                      data: evolutionData.data.map(d => d.expense),
                      borderColor: '#ef4444',
                      backgroundColor: 'rgba(239, 68, 68, 0.1)',
                      fill: true,
                      tension: 0.3,
                    },
                    {
                      label: t('reports.balance'),
                      data: evolutionData.data.map(d => d.balance),
                      borderColor: '#3b82f6',
                      backgroundColor: 'transparent',
                      borderDash: [5, 5],
                      tension: 0.3,
                    },
                  ],
                }}
                options={chartOptions}
              />
            </div>
          </div>
        </div>

        {/* Savings Rate Chart */}
        <div className="col-12">
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className={`card-header border-0 bg-transparent ${isMobile ? 'p-2' : ''}`}>
              <h6 className="text-white mb-0" style={{ fontSize: isMobile ? '0.85rem' : '1rem' }}>
                <i className="bi bi-percent me-2"></i>
                {t('reports.savingsRate')} por mes
              </h6>
            </div>
            <div className={isMobile ? 'p-2' : 'card-body'} style={{ height: isMobile ? '200px' : '250px' }}>
              <Bar
                data={{
                  labels: evolutionData.data.map(d => d.month_label),
                  datasets: [{
                    label: t('reports.savingsRate'),
                    data: evolutionData.data.map(d => d.savings_rate),
                    backgroundColor: evolutionData.data.map(d => 
                      d.savings_rate >= 20 ? 'rgba(16, 185, 129, 0.7)' :
                      d.savings_rate >= 10 ? 'rgba(245, 158, 11, 0.7)' :
                      d.savings_rate >= 0 ? 'rgba(239, 68, 68, 0.5)' :
                      'rgba(239, 68, 68, 0.8)'
                    ),
                    borderRadius: 4,
                  }],
                }}
                options={{
                  ...chartOptions,
                  plugins: {
                    ...chartOptions.plugins,
                    legend: { display: false }
                  }
                }}
              />
            </div>
          </div>
        </div>
      </div>
    );
  };

  // Render Comparison Tab
  const renderComparison = () => {
    if (!comparison) return null;

    return (
      <div className="row g-4">
        {/* Header com seletor de períodos */}
        <div className="col-12">
          <div className="d-flex align-items-center justify-content-between mb-3">
            <h5 className="text-white mb-0">
              <i className="bi bi-arrow-left-right me-2"></i>
              {t('reports.periodComparison')}
            </h5>
          </div>
        </div>

        {/* Cards KPI Comparativos */}
        <div className="col-lg-4 col-md-6">
          <div className="card border-0 h-100" style={{ background: 'linear-gradient(135deg, #059669 0%, #047857 100%)' }}>
            <div className="card-body text-white">
              <div className="d-flex align-items-center justify-content-between mb-3">
                <div>
                  <div className="opacity-75 small text-uppercase fw-semibold mb-1">{t('reports.income')}</div>
                  <h3 className="mb-0 fw-bold">{currency(comparison.period1.income, comparison.currency)}</h3>
                </div>
                <div className="fs-1 opacity-50">
                  <i className="bi bi-arrow-up-circle"></i>
                </div>
              </div>
              
              <div className="d-flex align-items-center gap-2 mb-2">
                {comparison.variation.income !== 0 && !isNaN(comparison.variation.income) && isFinite(comparison.variation.income) && (
                  <>
                    <span className={`badge ${comparison.variation.income >= 0 ? 'bg-white text-success' : 'bg-white text-danger'} px-2 py-1`}>
                      <i className={`bi bi-arrow-${comparison.variation.income >= 0 ? 'up' : 'down'} me-1`}></i>
                      {comparison.variation.income > 0 ? '+' : ''}{Math.abs(comparison.variation.income).toFixed(1)}%
                    </span>
                    <small className="opacity-75">{t('reports.vsPreviousPeriod')}</small>
                  </>
                )}
              </div>

              <hr className="my-2 opacity-25" />
              
              <div className="small">
                <div className="d-flex justify-content-between opacity-75">
                  <span>{comparison.period2.label}:</span>
                  <span className="fw-semibold">{currency(comparison.period2.income, comparison.currency)}</span>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div className="col-lg-4 col-md-6">
          <div className="card border-0 h-100" style={{ background: 'linear-gradient(135deg, #dc2626 0%, #b91c1c 100%)' }}>
            <div className="card-body text-white">
              <div className="d-flex align-items-center justify-content-between mb-3">
                <div>
                  <div className="opacity-75 small text-uppercase fw-semibold mb-1">{t('reports.expenses')}</div>
                  <h3 className="mb-0 fw-bold">{currency(comparison.period1.expense, comparison.currency)}</h3>
                </div>
                <div className="fs-1 opacity-50">
                  <i className="bi bi-arrow-down-circle"></i>
                </div>
              </div>
              
              <div className="d-flex align-items-center gap-2 mb-2">
                {comparison.variation.expense !== 0 && !isNaN(comparison.variation.expense) && isFinite(comparison.variation.expense) && (
                  <>
                    <span className={`badge ${comparison.variation.expense <= 0 ? 'bg-white text-success' : 'bg-white text-danger'} px-2 py-1`}>
                      <i className={`bi bi-arrow-${comparison.variation.expense >= 0 ? 'up' : 'down'} me-1`}></i>
                      {comparison.variation.expense > 0 ? '+' : ''}{Math.abs(comparison.variation.expense).toFixed(1)}%
                    </span>
                    <small className="opacity-75">{t('reports.vsPreviousPeriod')}</small>
                  </>
                )}
              </div>

              <hr className="my-2 opacity-25" />
              
              <div className="small">
                <div className="d-flex justify-content-between opacity-75">
                  <span>{comparison.period2.label}:</span>
                  <span className="fw-semibold">{currency(comparison.period2.expense, comparison.currency)}</span>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div className="col-lg-4 col-md-12">
          <div className="card border-0 h-100" style={{ background: 'linear-gradient(135deg, #3b82f6 0%, #2563eb 100%)' }}>
            <div className="card-body text-white">
              <div className="d-flex align-items-center justify-content-between mb-3">
                <div>
                  <div className="opacity-75 small text-uppercase fw-semibold mb-1">{t('reports.balance')}</div>
                  <h3 className="mb-0 fw-bold">{currency(comparison.period1.balance, comparison.currency)}</h3>
                </div>
                <div className="fs-1 opacity-50">
                  <i className="bi bi-wallet2"></i>
                </div>
              </div>
              
              <div className="d-flex align-items-center gap-2 mb-2">
                {comparison.variation.balance !== 0 && !isNaN(comparison.variation.balance) && isFinite(comparison.variation.balance) && (
                  <>
                    <span className={`badge ${comparison.variation.balance >= 0 ? 'bg-white text-success' : 'bg-white text-danger'} px-2 py-1`}>
                      <i className={`bi bi-arrow-${comparison.variation.balance >= 0 ? 'up' : 'down'} me-1`}></i>
                      {comparison.variation.balance > 0 ? '+' : ''}{Math.abs(comparison.variation.balance).toFixed(1)}%
                    </span>
                    <small className="opacity-75">{t('reports.vsPreviousPeriod')}</small>
                  </>
                )}
              </div>

              <hr className="my-2 opacity-25" />
              
              <div className="small">
                <div className="d-flex justify-content-between opacity-75">
                  <span>{comparison.period2.label}:</span>
                  <span className="fw-semibold">{currency(comparison.period2.balance, comparison.currency)}</span>
                </div>
              </div>
            </div>
          </div>
        </div>

        {/* Tabela Comparativa Detalhada */}
        <div className="col-lg-5">
          <div className="card border-0 h-100" style={{ background: '#0f172a' }}>
            <div className="card-header border-0 bg-transparent">
              <h6 className="text-white mb-0">
                <i className="bi bi-table me-2"></i>
                {t('reports.detailedComparison')}
              </h6>
            </div>
            <div className="card-body">
              <table className="table table-dark table-borderless mb-0">
                <thead className="border-bottom border-secondary">
                  <tr>
                    <th className="text-slate-400 fw-normal small">{t('reports.metric')}</th>
                    <th className="text-end text-slate-400 fw-normal small">{comparison.period2.label}</th>
                    <th className="text-end text-slate-400 fw-normal small">{comparison.period1.label}</th>
                    <th className="text-end text-slate-400 fw-normal small">{t('reports.variation')}</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td className="text-white">{t('reports.income')}</td>
                    <td className="text-end text-success">{currency(comparison.period2.income, comparison.currency)}</td>
                    <td className="text-end text-success fw-bold">{currency(comparison.period1.income, comparison.currency)}</td>
                    <td className="text-end">
                      {comparison.variation.income !== 0 && !isNaN(comparison.variation.income) && isFinite(comparison.variation.income) && (
                        <span className={`badge ${comparison.variation.income >= 0 ? 'bg-success' : 'bg-danger'}`}>
                          {comparison.variation.income > 0 ? '+' : ''}{comparison.variation.income.toFixed(1)}%
                        </span>
                      )}
                    </td>
                  </tr>
                  <tr>
                    <td className="text-white">{t('reports.expenses')}</td>
                    <td className="text-end text-danger">{currency(comparison.period2.expense, comparison.currency)}</td>
                    <td className="text-end text-danger fw-bold">{currency(comparison.period1.expense, comparison.currency)}</td>
                    <td className="text-end">
                      {comparison.variation.expense !== 0 && !isNaN(comparison.variation.expense) && isFinite(comparison.variation.expense) && (
                        <span className={`badge ${comparison.variation.expense <= 0 ? 'bg-success' : 'bg-danger'}`}>
                          {comparison.variation.expense > 0 ? '+' : ''}{comparison.variation.expense.toFixed(1)}%
                        </span>
                      )}
                    </td>
                  </tr>
                  <tr className="border-top border-secondary">
                    <td className="text-white fw-bold">{t('reports.balance')}</td>
                    <td className={`text-end fw-bold ${comparison.period2.balance >= 0 ? 'text-success' : 'text-danger'}`}>
                      {currency(comparison.period2.balance, comparison.currency)}
                    </td>
                    <td className={`text-end fw-bold ${comparison.period1.balance >= 0 ? 'text-success' : 'text-danger'}`}>
                      {currency(comparison.period1.balance, comparison.currency)}
                    </td>
                    <td className="text-end">
                      {comparison.variation.balance !== 0 && !isNaN(comparison.variation.balance) && isFinite(comparison.variation.balance) && (
                        <span className={`badge ${comparison.variation.balance >= 0 ? 'bg-success' : 'bg-danger'}`}>
                          {comparison.variation.balance > 0 ? '+' : ''}{comparison.variation.balance.toFixed(1)}%
                        </span>
                      )}
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        </div>

        {/* Gráfico de Barras Agrupadas */}
        <div className="col-lg-7">
          <div className="card border-0 h-100" style={{ background: '#0f172a' }}>
            <div className="card-header border-0 bg-transparent">
              <h6 className="text-white mb-0">
                <i className="bi bi-bar-chart-line me-2"></i>
                {t('reports.visualComparison')}
              </h6>
            </div>
            <div className="card-body" style={{ height: '320px' }}>
              <Bar
                data={{
                  labels: [t('reports.income'), t('reports.expenses'), t('reports.balance')],
                  datasets: [
                    {
                      label: comparison.period2.label,
                      data: [comparison.period2.income, comparison.period2.expense, comparison.period2.balance],
                      backgroundColor: 'rgba(100, 116, 139, 0.6)',
                      borderColor: '#64748b',
                      borderWidth: 2,
                      borderRadius: 6,
                    },
                    {
                      label: comparison.period1.label,
                      data: [comparison.period1.income, comparison.period1.expense, comparison.period1.balance],
                      backgroundColor: ['rgba(16, 185, 129, 0.8)', 'rgba(239, 68, 68, 0.8)', 'rgba(59, 130, 246, 0.8)'],
                      borderColor: ['#10b981', '#ef4444', '#3b82f6'],
                      borderWidth: 2,
                      borderRadius: 6,
                    },
                  ],
                }}
                options={{
                  ...chartOptions,
                  plugins: {
                    ...chartOptions.plugins,
                    legend: {
                      position: 'top',
                      labels: { 
                        color: '#94a3b8',
                        padding: 15,
                        font: { size: 12, weight: 'bold' }
                      }
                    },
                    tooltip: {
                      backgroundColor: 'rgba(15, 23, 42, 0.95)',
                      titleColor: '#fff',
                      bodyColor: '#94a3b8',
                      borderColor: '#334155',
                      borderWidth: 1,
                      padding: 12,
                      displayColors: true,
                      callbacks: {
                        label: function(context) {
                          return `${context.dataset.label}: ${currency(context.parsed.y, comparison.currency)}`;
                        }
                      }
                    }
                  }
                }}
              />
            </div>
          </div>
        </div>
      </div>
    );
  };

  // Render Top Expenses Tab
  const renderTopExpenses = () => {
    if (!topExpenses) return null;

    const top10 = topExpenses.data.slice(0, 10);
    const averageExpense = topExpenses.total / topExpenses.data.length;
    const maxExpense = topExpenses.data.length > 0 ? topExpenses.data[0].amount : 0;
    const minExpense = topExpenses.data.length > 0 ? topExpenses.data[topExpenses.data.length - 1].amount : 0;

    return (
      <div className="row g-4">
        {/* Header */}
        <div className="col-12">
          <div className="d-flex align-items-center justify-content-between mb-3">
            <h5 className="text-white mb-0">
              <i className="bi bi-sort-down me-2"></i>
              {t('reports.topExpensesAnalysis')}
            </h5>
            <span className="badge bg-danger fs-6 px-3 py-2">
              {t('reports.total')}: {currency(topExpenses.total, topExpenses.currency)}
            </span>
          </div>
        </div>

        {/* Cards KPI */}
        <div className="col-lg-3 col-md-6">
          <div className="card border-0" style={{ background: 'linear-gradient(135deg, #EF4444 0%, #DC2626 100%)' }}>
            <div className="card-body text-white">
              <div className="d-flex align-items-center justify-content-between">
                <div>
                  <div className="opacity-75 small text-uppercase fw-semibold mb-1">{t('reports.highestExpense')}</div>
                  <h4 className="mb-0 fw-bold">{currency(maxExpense, topExpenses.currency)}</h4>
                </div>
                <div className="fs-1 opacity-50">
                  <i className="bi bi-exclamation-triangle"></i>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div className="col-lg-3 col-md-6">
          <div className="card border-0" style={{ background: 'linear-gradient(135deg, #F59E0B 0%, #D97706 100%)' }}>
            <div className="card-body text-white">
              <div className="d-flex align-items-center justify-content-between">
                <div>
                  <div className="opacity-75 small text-uppercase fw-semibold mb-1">{t('reports.averageExpense')}</div>
                  <h4 className="mb-0 fw-bold">{currency(averageExpense, topExpenses.currency)}</h4>
                </div>
                <div className="fs-1 opacity-50">
                  <i className="bi bi-graph-down"></i>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div className="col-lg-3 col-md-6">
          <div className="card border-0" style={{ background: 'linear-gradient(135deg, #10B981 0%, #059669 100%)' }}>
            <div className="card-body text-white">
              <div className="d-flex align-items-center justify-content-between">
                <div>
                  <div className="opacity-75 small text-uppercase fw-semibold mb-1">{t('reports.lowestExpense')}</div>
                  <h4 className="mb-0 fw-bold">{currency(minExpense, topExpenses.currency)}</h4>
                </div>
                <div className="fs-1 opacity-50">
                  <i className="bi bi-check-circle"></i>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div className="col-lg-3 col-md-6">
          <div className="card border-0" style={{ background: 'linear-gradient(135deg, #8B5CF6 0%, #7C3AED 100%)' }}>
            <div className="card-body text-white">
              <div className="d-flex align-items-center justify-content-between">
                <div>
                  <div className="opacity-75 small text-uppercase fw-semibold mb-1">{t('reports.totalTransactions')}</div>
                  <h4 className="mb-0 fw-bold">{topExpenses.data.length}</h4>
                </div>
                <div className="fs-1 opacity-50">
                  <i className="bi bi-list-ul"></i>
                </div>
              </div>
            </div>
          </div>
        </div>

        {/* Gráfico de Barras Horizontais - Top 10 */}
        <div className="col-12">
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className="card-header border-0 bg-transparent">
              <h6 className="text-white mb-0">
                <i className="bi bi-bar-chart-line me-2"></i>
                {t('reports.top10Expenses')}
              </h6>
            </div>
            <div className="card-body" style={{ height: '400px' }}>
              <Bar
                data={{
                  labels: top10.map((item, i) => `${i + 1}. ${item.description.substring(0, 30)}${item.description.length > 30 ? '...' : ''}`),
                  datasets: [{
                    label: t('reports.amount'),
                    data: top10.map(item => item.amount),
                    backgroundColor: top10.map((_, i) => {
                      const opacity = 1 - (i * 0.08);
                      return `rgba(239, 68, 68, ${opacity})`;
                    }),
                    borderColor: '#EF4444',
                    borderWidth: 2,
                    borderRadius: 6,
                  }],
                }}
                options={{
                  indexAxis: 'y',
                  responsive: true,
                  maintainAspectRatio: false,
                  plugins: {
                    legend: { display: false },
                    tooltip: {
                      backgroundColor: 'rgba(15, 23, 42, 0.95)',
                      titleColor: '#fff',
                      bodyColor: '#94a3b8',
                      borderColor: '#334155',
                      borderWidth: 1,
                      padding: 12,
                      callbacks: {
                        label: function(context) {
                          const item = top10[context.dataIndex];
                          return [
                            `${t('reports.amount')}: ${currency(context.parsed.x, topExpenses.currency)}`,
                            `${t('reports.category')}: ${item.category || '-'}`,
                            `${t('reports.date')}: ${item.date}`
                          ];
                        }
                      }
                    }
                  },
                  scales: {
                    x: {
                      ticks: { 
                        color: '#94a3b8',
                        callback: function(value) {
                          return currency(value, topExpenses.currency);
                        }
                      },
                      grid: { color: 'rgba(148, 163, 184, 0.1)' }
                    },
                    y: {
                      ticks: { 
                        color: '#94a3b8',
                        font: { size: 11 }
                      },
                      grid: { display: false }
                    }
                  }
                }}
              />
            </div>
          </div>
        </div>

        {/* Tabela/Lista Detalhada */}
        <div className="col-12">
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className={`card-header border-0 bg-transparent ${isMobile ? 'p-2' : ''}`}>
              <h6 className="text-white mb-0" style={{ fontSize: isMobile ? '0.85rem' : '1rem' }}>
                <i className="bi bi-table me-2"></i>
                {t('reports.detailedList')} ({topExpenses.data.length} {t('reports.transactions')})
              </h6>
            </div>
            <div className={isMobile ? 'p-2' : 'card-body p-0'}>
              {/* Desktop: Tabela */}
              {!isMobile && (
                <div className="table-responsive" style={{ maxHeight: '500px' }}>
                  <table className="table table-dark table-hover mb-0">
                    <thead className="sticky-top" style={{ background: '#1e293b' }}>
                      <tr>
                        <th className="text-center" style={{ width: '60px' }}>#</th>
                        <th>{t('reports.description')}</th>
                        <th>{t('reports.category')}</th>
                        <th className="text-center">{t('reports.date')}</th>
                        <th className="text-end">{t('reports.amount')}</th>
                        <th className="text-center" style={{ width: '100px' }}>% {t('reports.total')}</th>
                      </tr>
                    </thead>
                    <tbody>
                      {topExpenses.data.map((item, i) => {
                        const percentage = (item.amount / topExpenses.total) * 100;
                        return (
                          <tr key={item.id}>
                            <td className="text-center">
                              <span className={`badge ${i < 3 ? 'bg-danger' : i < 10 ? 'bg-warning text-dark' : 'bg-secondary'}`}>
                                {i + 1}
                              </span>
                            </td>
                            <td>
                              <div className="text-white text-truncate" style={{ maxWidth: '300px' }}>
                                {item.description}
                              </div>
                            </td>
                            <td>
                              <span className="badge bg-primary">{item.category || '-'}</span>
                            </td>
                            <td className="text-center text-slate-400 small">{item.date}</td>
                            <td className="text-end">
                              <span className="text-danger fw-bold">
                                {currency(item.amount, item.currency || topExpenses.currency)}
                              </span>
                            </td>
                            <td className="text-center">
                              <div className="d-flex align-items-center justify-content-center gap-2">
                                <div className="progress flex-grow-1" style={{ height: '6px', width: '50px' }}>
                                  <div 
                                    className="progress-bar bg-danger" 
                                    style={{ width: `${percentage}%` }}
                                  ></div>
                                </div>
                                <small className="text-slate-400" style={{ minWidth: '45px' }}>
                                  {percentage.toFixed(1)}%
                                </small>
                              </div>
                            </td>
                          </tr>
                        );
                      })}
                    </tbody>
                  </table>
                </div>
              )}

              {/* Mobile: Cards compactos */}
              {isMobile && (
                <div style={{ maxHeight: '500px', overflowY: 'auto' }}>
                  {topExpenses.data.map((item, i) => {
                    const percentage = (item.amount / topExpenses.total) * 100;
                    return (
                      <div 
                        key={item.id}
                        className="card mb-2 border-0"
                        style={{ background: '#1e293b' }}
                      >
                        <div className="card-body p-2">
                          {/* Header: Ranking e Valor */}
                          <div className="d-flex justify-content-between align-items-start mb-2">
                            <span className={`badge ${i < 3 ? 'bg-danger' : i < 10 ? 'bg-warning text-dark' : 'bg-secondary'}`} style={{ fontSize: '0.75rem' }}>
                              #{i + 1}
                            </span>
                            <div className="text-end">
                              <div className="text-danger fw-bold" style={{ fontSize: '0.95rem' }}>
                                {currency(item.amount, item.currency || topExpenses.currency)}
                              </div>
                              <small className="text-slate-400" style={{ fontSize: '0.7rem' }}>
                                {percentage.toFixed(1)}%
                              </small>
                            </div>
                          </div>

                          {/* Descrição */}
                          <div className="text-white mb-1" style={{ fontSize: '0.85rem', lineHeight: '1.3' }}>
                            {item.description}
                          </div>

                          {/* Footer: Categoria e Data */}
                          <div className="d-flex justify-content-between align-items-center">
                            <span className="badge bg-primary" style={{ fontSize: '0.7rem' }}>
                              {item.category || '-'}
                            </span>
                            <small className="text-slate-400" style={{ fontSize: '0.7rem' }}>
                              {item.date}
                            </small>
                          </div>

                          {/* Progress bar */}
                          <div className="progress mt-2" style={{ height: '4px' }}>
                            <div 
                              className="progress-bar bg-danger" 
                              style={{ width: `${percentage}%` }}
                            ></div>
                          </div>
                        </div>
                      </div>
                    );
                  })}
                </div>
              )}
            </div>
          </div>
        </div>
      </div>
    );
  };

  // Render Projection Tab
  const renderProjection = () => {
    return (
      <div className="row g-4">
        {/* Balance Projection Chart - Full Width First */}
        <div className="col-12">
          <BalanceProjectionChart />
        </div>

        {projection && (
          <>
            <div className="col-md-6">
              <div className="card border-0" style={{ background: '#1e293b' }}>
                <div className="card-header border-0 bg-transparent">
                  <h6 className="text-white mb-0">
                    <i className="bi bi-calendar3 me-2"></i>
                    {t('reports.currentMonth')}
                  </h6>
                </div>
                <div className="card-body">
                  <div className="d-flex justify-content-between mb-3">
                    <span className="text-slate-400">{t('reports.income')}</span>
                    <span className="text-success">{currency(projection.current_month.income, projection.currency)}</span>
                  </div>
                  <div className="d-flex justify-content-between mb-3">
                    <span className="text-slate-400">{t('reports.expenses')}</span>
                    <span className="text-danger">{currency(projection.current_month.expense, projection.currency)}</span>
                  </div>
                  <hr className="border-secondary" />
                  <div className="d-flex justify-content-between">
                    <span className="text-slate-400">{t('reports.daysRemaining')}</span>
                    <span className="text-white">{projection.current_month.days_remaining} {t('common.days')}</span>
                  </div>
                </div>
              </div>
            </div>

            <div className="col-md-6">
              <div className="card border-0" style={{ background: 'linear-gradient(135deg, #1e40af 0%, #3b82f6 100%)' }}>
                <div className="card-header border-0 bg-transparent">
                  <h6 className="text-white mb-0">
                    <i className="bi bi-lightning me-2"></i>
                    {t('reports.projectionTitle')}
                  </h6>
                </div>
                <div className="card-body text-white">
                  <div className="d-flex justify-content-between mb-3">
                    <span className="opacity-75">{t('reports.projectedIncome')}</span>
                    <span className="fw-bold">{currency(projection.projection.income, projection.currency)}</span>
                  </div>
                  <div className="d-flex justify-content-between mb-3">
                    <span className="opacity-75">{t('reports.projectedExpense')}</span>
                    <span className="fw-bold">{currency(projection.projection.expense, projection.currency)}</span>
                  </div>
                  <hr className="border-white opacity-25" />
                  <div className="d-flex justify-content-between">
                    <span className="opacity-75">{t('reports.balance')}</span>
                    <span className={`fw-bold ${projection.projection.balance >= 0 ? '' : 'text-warning'}`}>
                      {currency(projection.projection.balance, projection.currency)}
                    </span>
                  </div>
                </div>
              </div>
            </div>

            {/* vs Average */}
            <div className="col-12">
              <div className="card border-0" style={{ background: '#0f172a' }}>
                <div className="card-header border-0 bg-transparent">
                  <h6 className="text-white mb-0">
                    <i className="bi bi-bar-chart me-2"></i>
                    {t('reports.vsAverage')} ({t('reports.last3Months')})
                  </h6>
                </div>
                <div className="card-body" style={{ height: '250px' }}>
                  <Bar
                    data={{
                      labels: [t('reports.income'), t('reports.expenses')],
                      datasets: [
                        {
                          label: t('reports.historicalAverage'),
                          data: [projection.historical_average.income, projection.historical_average.expense],
                          backgroundColor: 'rgba(148, 163, 184, 0.5)',
                          borderRadius: 4,
                        },
                        {
                          label: t('reports.monthProjection'),
                          data: [projection.projection.income, projection.projection.expense],
                          backgroundColor: ['rgba(16, 185, 129, 0.7)', 'rgba(239, 68, 68, 0.7)'],
                          borderRadius: 4,
                        },
                      ],
                    }}
                    options={chartOptions}
                  />
                </div>
              </div>
            </div>
          </>
        )}
      </div>
    );
  };

  // Render Day of Week Tab
  const renderDayOfWeek = () => {
    if (!dayOfWeekData || !dayOfWeekData.data) return null;
    const data = dayOfWeekData.data;

    return (
      <div className="row g-4">
        <div className="col-12">
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className="card-header border-0 bg-transparent">
              <h6 className="text-white mb-0">
                <i className="bi bi-calendar-week me-2"></i>
                {t('reports.expensesByDayOfWeek')}
              </h6>
            </div>
            <div className="card-body" style={{ height: '300px' }}>
              <Bar
                data={{
                  labels: data.map(d => t(`reports.dayOfWeek.${d.day_key}`)),
                  datasets: [{
                    label: t('reports.totalSpent'),
                    data: data.map(d => d.total),
                    backgroundColor: data.map(d => 
                      d.day_num === 1 || d.day_num === 7 
                        ? 'rgba(245, 158, 11, 0.7)' 
                        : 'rgba(59, 130, 246, 0.7)'
                    ),
                    borderRadius: 4,
                  }],
                }}
                options={{
                  ...chartOptions,
                  plugins: { ...chartOptions.plugins, legend: { display: false } }
                }}
              />
            </div>
          </div>
        </div>

        <div className="col-12">
          <div className="card border-0" style={{ background: '#1e293b' }}>
            <div className="card-body p-0">
              <table className="table table-dark mb-0">
                <thead>
                  <tr>
                    <th>{t('reports.dayOfWeek.day')}</th>
                    <th className="text-center">{t('transactions.title')}</th>
                    <th className="text-end">{t('common.total')}</th>
                    <th className="text-end">{t('reports.avgExpense')}</th>
                  </tr>
                </thead>
                <tbody>
                  {dayOfWeekData.data.map(d => (
                    <tr key={d.day_num}>
                      <td>
                        <i className={`bi bi-calendar3 me-2 ${d.day_num === 1 || d.day_num === 7 ? 'text-warning' : 'text-primary'}`}></i>
                        {t(`reports.dayOfWeek.${d.day_key}`)}
                      </td>
                      <td className="text-center"><span className="badge bg-secondary">{d.count}</span></td>
                      <td className="text-end text-danger">{currency(d.total, dayOfWeekData.currency)}</td>
                      <td className="text-end text-slate-400">{currency(d.average, dayOfWeekData.currency)}</td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    );
  };

  // Render Cost Center Tab
  const renderCostCenter = () => {
    if (!costCenterData) return null;
    const data = costCenterData.data || [];

    return (
      <div className="row g-4">
        <div className="col-md-4">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.totalIncome')}</small>
              <h5 className="text-success mb-0">{currency(costCenterData.total_income || 0, costCenterData.currency)}</h5>
            </div>
          </div>
        </div>
        <div className="col-md-4">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.totalExpense')}</small>
              <h5 className="text-danger mb-0">{currency(costCenterData.total_expense || 0, costCenterData.currency)}</h5>
            </div>
          </div>
        </div>
        <div className="col-md-4">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.balance')}</small>
              <h5 className={`mb-0 ${(costCenterData.total_income - costCenterData.total_expense) >= 0 ? 'text-success' : 'text-danger'}`}>
                {currency((costCenterData.total_income || 0) - (costCenterData.total_expense || 0), costCenterData.currency)}
              </h5>
            </div>
          </div>
        </div>

        <div className="col-12">
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className="card-header border-0 bg-transparent">
              <h6 className="text-white mb-0">
                <i className="bi bi-diagram-3 me-2"></i>
                {t('reports.byCostCenter')}
              </h6>
            </div>
            <div className="card-body p-0">
              <div className="table-responsive">
                <table className="table table-dark table-hover mb-0">
                  <thead>
                    <tr>
                      <th>{t('costCenters.name')}</th>
                      <th className="text-end">{t('reports.income')}</th>
                      <th className="text-end">{t('reports.expenses')}</th>
                      <th className="text-end">{t('reports.balance')}</th>
                    </tr>
                  </thead>
                  <tbody>
                    {data.map(cc => (
                      <tr key={cc.id}>
                        <td>
                          <span className="me-2" style={{ color: cc.color || '#6b7280' }}>●</span>
                          {cc.name}
                        </td>
                        <td className="text-end text-success">{currency(cc.income, costCenterData.currency)}</td>
                        <td className="text-end text-danger">{currency(cc.expense, costCenterData.currency)}</td>
                        <td className={`text-end ${cc.balance >= 0 ? 'text-success' : 'text-danger'}`}>
                          {currency(cc.balance, costCenterData.currency)}
                        </td>
                      </tr>
                    ))}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  };

  // Render Recurring Tab
  const renderRecurring = () => {
    if (!recurringData) return null;
    const templates = recurringData.templates || [];
    const summary = recurringData.summary || {};

    return (
      <div className="row g-4">
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.totalRecurring')}</small>
              <h4 className="text-white mb-0">{summary.total_recurring || 0}</h4>
            </div>
          </div>
        </div>
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.monthlyIncome')}</small>
              <h5 className="text-success mb-0">{currency(summary.monthly_income || 0, recurringData.currency)}</h5>
            </div>
          </div>
        </div>
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.monthlyExpense')}</small>
              <h5 className="text-danger mb-0">{currency(summary.monthly_expense || 0, recurringData.currency)}</h5>
            </div>
          </div>
        </div>
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.netRecurring')}</small>
              <h5 className={`mb-0 ${(summary.net_recurring || 0) >= 0 ? 'text-success' : 'text-danger'}`}>
                {currency(summary.net_recurring || 0, recurringData.currency)}
              </h5>
            </div>
          </div>
        </div>

        <div className="col-12">
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className="card-header border-0 bg-transparent">
              <h6 className="text-white mb-0">
                <i className="bi bi-arrow-repeat me-2"></i>
                {t('reports.recurringList')}
              </h6>
            </div>
            <div className="card-body p-0">
              <div className="table-responsive">
                <table className="table table-dark table-hover mb-0">
                  <thead>
                    <tr>
                      <th>{t('common.description')}</th>
                      <th>{t('reports.category')}</th>
                      <th>{t('recurring.frequency')}</th>
                      <th>{t('reports.nextDate')}</th>
                      <th className="text-end">{t('reports.amount')}</th>
                    </tr>
                  </thead>
                  <tbody>
                    {templates.map(t => (
                      <tr key={t.id}>
                        <td>{t.description}</td>
                        <td>
                          {t.category && (
                            <span className="badge" style={{ background: t.category_color || '#6b7280' }}>
                              <i className={`bi ${t.category_icon || 'bi-tag'} me-1`}></i>
                              {t.category}
                            </span>
                          )}
                        </td>
                        <td><span className="badge bg-secondary">{t.frequency}</span></td>
                        <td className="text-slate-400">{t.next_date}</td>
                        <td className={`text-end fw-bold ${t.type === 'credit' ? 'text-success' : 'text-danger'}`}>
                          {t.type === 'credit' ? '+' : '-'}{currency(t.amount, t.currency)}
                        </td>
                      </tr>
                    ))}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  };

  // Render Liabilities Tab
  const renderLiabilities = () => {
    if (!liabilitiesData) return null;
    const data = liabilitiesData.data || [];
    const summary = liabilitiesData.summary || {};

    return (
      <div className="row g-4">
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.totalLiabilities')}</small>
              <h4 className="text-white mb-0">{summary.total_liabilities || 0}</h4>
            </div>
          </div>
        </div>
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.totalDebt')}</small>
              <h5 className="text-danger mb-0">{currency(summary.total_debt || 0, liabilitiesData.currency)}</h5>
            </div>
          </div>
        </div>
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.totalPaid')}</small>
              <h5 className="text-success mb-0">{currency(summary.total_paid || 0, liabilitiesData.currency)}</h5>
            </div>
          </div>
        </div>
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.totalPending')}</small>
              <h5 className="text-warning mb-0">{currency(summary.total_pending || 0, liabilitiesData.currency)}</h5>
            </div>
          </div>
        </div>

        {data.map(liability => (
          <div key={liability.id} className="col-md-6">
            <div className="card border-0" style={{ background: '#0f172a' }}>
              <div className="card-body">
                <div className="d-flex justify-content-between align-items-start mb-3">
                  <div>
                    <h6 className="text-white mb-1">{liability.name}</h6>
                    <span className="badge bg-secondary">{liability.type}</span>
                  </div>
                  {liability.overdue_installments > 0 && (
                    <span className="badge bg-danger">
                      {liability.overdue_installments} {t('reports.overdueInstallments')}
                    </span>
                  )}
                </div>
                
                <div className="progress mb-3" style={{ height: '8px' }}>
                  <div 
                    className="progress-bar bg-success" 
                    style={{ width: `${liability.progress || 0}%` }}
                  ></div>
                </div>
                
                <div className="d-flex justify-content-between text-sm">
                  <span className="text-slate-400">
                    {liability.paid_installments}/{liability.total_installments} {t('reports.installments')}
                  </span>
                  <span className="text-success">{liability.progress?.toFixed(1)}%</span>
                </div>
                
                <hr className="border-secondary my-3" />
                
                <div className="row text-center">
                  <div className="col-4">
                    <small className="text-slate-400 d-block">{t('common.total')}</small>
                    <span className="text-white">{currency(liability.total_amount, liability.currency)}</span>
                  </div>
                  <div className="col-4">
                    <small className="text-slate-400 d-block">{t('reports.paid')}</small>
                    <span className="text-success">{currency(liability.paid_amount, liability.currency)}</span>
                  </div>
                  <div className="col-4">
                    <small className="text-slate-400 d-block">{t('reports.pending')}</small>
                    <span className="text-warning">{currency(liability.pending_amount, liability.currency)}</span>
                  </div>
                </div>

                {liability.next_installment && (
                  <div className={`mt-3 p-2 rounded ${liability.next_installment.is_overdue ? 'bg-danger bg-opacity-25' : 'bg-primary bg-opacity-25'}`}>
                    <small className="text-slate-400">{t('reports.nextInstallment')}:</small>
                    <div className="d-flex justify-content-between">
                      <span className="text-white">{formatDate(liability.next_installment.due_date)}</span>
                      <span className={liability.next_installment.is_overdue ? 'text-danger' : 'text-primary'}>
                        {currency(liability.next_installment.amount, liability.currency)}
                      </span>
                    </div>
                  </div>
                )}
              </div>
            </div>
          </div>
        ))}
      </div>
    );
  };

  // Render Future Transactions Tab
  const renderFuture = () => {
    if (!futureData) return null;
    const data = futureData.data || [];
    const summary = futureData.summary || {};

    return (
      <div className="row g-4">
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.totalTransactions')}</small>
              <h4 className="text-white mb-0">{summary.total_transactions || 0}</h4>
            </div>
          </div>
        </div>
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.futureIncome')}</small>
              <h5 className="text-success mb-0">{currency(summary.total_income || 0, futureData.currency)}</h5>
            </div>
          </div>
        </div>
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.futureExpense')}</small>
              <h5 className="text-danger mb-0">{currency(summary.total_expense || 0, futureData.currency)}</h5>
            </div>
          </div>
        </div>
        <div className="col-md-3">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.netImpact')}</small>
              <h5 className={`mb-0 ${(summary.net_impact || 0) >= 0 ? 'text-success' : 'text-danger'}`}>
                {currency(summary.net_impact || 0, futureData.currency)}
              </h5>
            </div>
          </div>
        </div>

        <div className="col-12">
          <div className="card border-0" style={{ background: '#0f172a' }}>
            <div className="card-header border-0 bg-transparent">
              <h6 className="text-white mb-0">
                <i className="bi bi-calendar-plus me-2"></i>
                {t('reports.next30Days')}
              </h6>
            </div>
            <div className="card-body p-0">
              <div className="table-responsive">
                <table className="table table-dark table-hover mb-0">
                  <thead>
                    <tr>
                      <th>{t('reports.date')}</th>
                      <th>{t('common.description')}</th>
                      <th>{t('reports.category')}</th>
                      <th>{t('reports.account')}</th>
                      <th className="text-end">{t('reports.amount')}</th>
                    </tr>
                  </thead>
                  <tbody>
                    {data.map(tx => (
                      <tr key={tx.id}>
                        <td>
                          <span className="badge bg-primary">{tx.days_until}d</span>
                          <span className="text-slate-400 ms-2">{tx.date}</span>
                        </td>
                        <td>{tx.description}</td>
                        <td>
                          {tx.category && (
                            <span className="badge bg-secondary">
                              <i className={`bi ${tx.category_icon || 'bi-tag'} me-1`}></i>
                              {tx.category}
                            </span>
                          )}
                        </td>
                        <td className="text-slate-400">{tx.account}</td>
                        <td className={`text-end fw-bold ${tx.type === 'credit' ? 'text-success' : 'text-danger'}`}>
                          {tx.type === 'credit' ? '+' : '-'}{currency(tx.amount, tx.currency)}
                        </td>
                      </tr>
                    ))}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  };

  // Render Overdue Tab
  const renderOverdue = () => {
    if (!overdueData) return null;
    const data = overdueData.data || [];
    const summary = overdueData.summary || {};

    return (
      <div className="row g-4">
        <div className="col-md-6">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.totalOverdue')}</small>
              <h4 className="text-danger mb-0">{summary.total_overdue || 0}</h4>
            </div>
          </div>
        </div>
        <div className="col-md-6">
          <div className="card border-0 text-center" style={{ background: '#1e293b' }}>
            <div className="card-body">
              <small className="text-slate-400">{t('reports.overdueAmount')}</small>
              <h5 className="text-danger mb-0">{currency(summary.total_amount || 0, overdueData.currency)}</h5>
            </div>
          </div>
        </div>

        {data.length === 0 ? (
          <div className="col-12">
            <div className="card border-0 text-center py-5" style={{ background: '#0f172a' }}>
              <div className="card-body">
                <i className="bi bi-check-circle text-success" style={{ fontSize: '4rem' }}></i>
                <h5 className="text-white mt-3">{t('reports.noOverdue')}</h5>
                <p className="text-slate-400">{t('reports.noOverdueDescription')}</p>
              </div>
            </div>
          </div>
        ) : (
          <div className="col-12">
            <div className="card border-0" style={{ background: '#0f172a' }}>
              <div className="card-header border-0 bg-transparent">
                <h6 className="text-white mb-0">
                  <i className="bi bi-exclamation-triangle text-danger me-2"></i>
                  {t('reports.overdueList')}
                </h6>
              </div>
              <div className="card-body p-0">
                <div className="table-responsive">
                  <table className="table table-dark table-hover mb-0">
                    <thead>
                      <tr>
                        <th>{t('common.description')}</th>
                        <th>{t('reports.dueDate')}</th>
                        <th>{t('reports.daysOverdue')}</th>
                        <th className="text-end">{t('reports.amount')}</th>
                      </tr>
                    </thead>
                    <tbody>
                      {data.map(item => (
                        <tr key={item.id}>
                          <td>{item.description}</td>
                          <td className="text-slate-400">{item.due_date}</td>
                          <td>
                            <span className="badge bg-danger">{item.days_overdue} {t('common.days')}</span>
                          </td>
                          <td className="text-end text-danger fw-bold">
                            {currency(item.amount, item.currency)}
                          </td>
                        </tr>
                      ))}
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>
        )}
      </div>
    );
  };

  const renderContent = () => {
    if (loading) {
      return (
        <div className="text-center py-5">
          <div className="spinner-border text-primary" role="status">
            <span className="visually-hidden">{t('common.loading')}</span>
          </div>
        </div>
      );
    }

    switch (activeTab) {
      case 'summary': return renderSummary();
      case 'category': return renderCategory();
      case 'costCenter': return renderCostCenter();
      case 'evolution': return renderEvolution();
      case 'comparison': return renderComparison();
      case 'topExpenses': return renderTopExpenses();
      case 'projection': return renderProjection();
      case 'recurring': return renderRecurring();
      case 'liabilities': return renderLiabilities();
      case 'future': return renderFuture();
      case 'overdue': return renderOverdue();
      default: return null;
    }
  };

  return (
    <div className="reports-container">
      {/* CSS para hover na tabela */}
      <style>{`
        .table-hover-row:hover {
          background-color: rgba(59, 130, 246, 0.1) !important;
          transition: background-color 0.2s ease;
        }
      `}</style>
      
      {/* Header */}
      <div className={`d-flex ${isMobile ? 'flex-column gap-2' : 'justify-content-between align-items-center'} mb-4`}>
        <div>
          <h4 className="text-white mb-1 fw-bold" style={{ fontSize: isMobile ? '1.1rem' : '1.5rem' }}>
            <i className="bi bi-bar-chart-line me-2"></i>
            {t('reports.title')}
          </h4>
          <p className="text-slate-400 mb-0" style={{ fontSize: isMobile ? '0.75rem' : '0.875rem' }}>
            {t('reports.subtitle')}
          </p>
        </div>
      </div>

      {/* Tabs */}
      <div className="card border-0 mb-4" style={{ background: '#0f172a' }}>
        <div className="card-body" style={{ padding: isMobile ? '0.5rem' : '0.75rem' }}>
          <div className="d-flex flex-wrap gap-1">
            {tabs.map(tab => (
              <button
                key={tab.id}
                className={`btn ${activeTab === tab.id ? 'btn-primary' : 'btn-outline-secondary'}`}
                onClick={() => setActiveTab(tab.id)}
                style={{ 
                  fontSize: isMobile ? '0.7rem' : '0.875rem',
                  padding: isMobile ? '0.25rem 0.5rem' : '0.375rem 0.75rem'
                }}
              >
                <i className={`bi ${tab.icon} ${isMobile ? '' : 'me-1'}`}></i>
                {isMobile ? '' : tab.label}
              </button>
            ))}
          </div>
        </div>
      </div>

      {/* Content */}
      {renderContent()}
    </div>
  );
};

export default Reports;
