/* ===== DASHBOARD — Expense Analytics ===== */

/* ---- Filter Bar ---- */
.dash-filter-bar {
    display: flex; flex-direction: column; gap: 12px;
    margin-bottom: 1.5rem; padding: 16px 20px;
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}
.dash-filter-presets {
    display: flex; gap: 6px; flex-wrap: wrap;
}
.dash-preset {
    padding: 6px 14px; font-family: var(--font-sans); font-size: 0.78rem; font-weight: 600;
    background: transparent; color: var(--muted-foreground); border: 1px solid var(--border);
    border-radius: 9999px; cursor: pointer; transition: all 0.25s ease;
    letter-spacing: 0.3px;
}
.dash-preset:hover {
    background: var(--muted); color: var(--foreground); border-color: var(--muted-foreground);
}
.dash-preset.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: var(--primary-foreground);
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}
.dash-filter-custom {
    display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}

/* ---- Loading & Error ---- */
.dash-loading, .dash-error {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 4rem 2rem; gap: 12px; color: var(--muted-foreground); font-size: 0.9rem;
}
.dash-error { color: var(--danger); }

/* ---- KPI Cards ---- */
.kpi-row {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem;
    margin-bottom: 1.5rem;
}
.kpi-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    display: flex; align-items: flex-start; gap: 14px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.25s ease, box-shadow 0.25s ease, background-color 0.3s ease, border-color 0.3s ease;
    animation: kpiSlideIn 0.5s ease backwards;
}
.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.1s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.2s; }
.kpi-card:nth-child(5) { animation-delay: 0.25s; }
.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}
.kpi-icon {
    width: 42px; height: 42px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: background-color 0.3s ease;
}

/* KPI icon variants — semi-transparent backgrounds that work in both themes */
.kpi-icon-total { background: rgba(139, 92, 246, 0.12); color: var(--primary); }
.kpi-icon-count { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.kpi-icon-avg   { background: rgba(34, 197, 94, 0.12);  color: var(--success); }
.kpi-icon-high  { background: rgba(239, 68, 68, 0.12);  color: var(--danger); }
.kpi-icon-cat   { background: rgba(168, 85, 247, 0.12); color: #a855f7; }

[data-theme="dark"] .kpi-icon-total { background: rgba(167, 139, 250, 0.15); color: #a78bfa; }
[data-theme="dark"] .kpi-icon-count { background: rgba(96, 165, 250, 0.15);  color: #60a5fa; }
[data-theme="dark"] .kpi-icon-avg   { background: rgba(74, 222, 128, 0.15);  color: #4ade80; }
[data-theme="dark"] .kpi-icon-high  { background: rgba(248, 113, 113, 0.15); color: #f87171; }
[data-theme="dark"] .kpi-icon-cat   { background: rgba(192, 132, 252, 0.15); color: #c084fc; }

.kpi-body { flex: 1; min-width: 0; }
.kpi-label {
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.6px; color: var(--muted-foreground); margin-bottom: 4px;
}
.kpi-value {
    font-family: var(--font-mono); font-size: 1.15rem; font-weight: 700;
    color: var(--foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

@keyframes kpiSlideIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Chart Grid ---- */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
.chart-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    animation: chartFadeIn 0.5s ease backwards;
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease, transform 0.2s ease;
}
.chart-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.chart-card:nth-child(1) { animation-delay: 0.1s; }
.chart-card:nth-child(2) { animation-delay: 0.15s; }
.chart-card:nth-child(3) { animation-delay: 0.2s; }
.chart-card:nth-child(4) { animation-delay: 0.25s; }
.chart-card:nth-child(5) { animation-delay: 0.3s; }
.chart-card:nth-child(6) { animation-delay: 0.35s; }

@keyframes chartFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}
.chart-card-header {
    padding: 16px 20px 0;
}
.chart-title {
    font-family: var(--font-sans); font-size: 1rem; font-weight: 600;
    color: var(--foreground); margin-bottom: 2px; letter-spacing: -0.01em;
}
.chart-subtitle {
    font-size: 0.72rem; color: var(--muted-foreground); font-weight: 500;
}
.chart-body {
    padding: 16px 20px 20px;
}
.chart-body canvas {
    width: 100% !important;
    display: block;
}
.chart-body-pie {
    display: flex; align-items: center; gap: 20px;
    flex-wrap: wrap; justify-content: center;
}
.chart-body-pie canvas {
    width: auto !important;
    flex-shrink: 0;
}

/* ---- Pie Legend ---- */
.pie-legend {
    display: flex; flex-direction: column; gap: 6px;
    flex: 1; min-width: 140px;
}
.pie-legend-item {
    display: flex; align-items: center; gap: 8px; font-size: 0.78rem;
    color: var(--foreground);
}
.pie-legend-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.pie-legend-label {
    flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-weight: 500;
}
.pie-legend-value {
    font-family: var(--font-mono); font-weight: 600; font-size: 0.76rem;
    color: var(--muted-foreground); white-space: nowrap;
}

/* ---- Top 5 Horizontal Bars ---- */
.top5-list {
    display: flex; flex-direction: column; gap: 14px;
}
.top5-item {
    display: flex; flex-direction: column; gap: 5px;
}
.top5-header {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 0.82rem;
}
.top5-name {
    font-weight: 600; color: var(--foreground);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%;
}
.top5-amount {
    font-family: var(--font-mono); font-weight: 600; font-size: 0.8rem;
    color: var(--muted-foreground);
}
.top5-bar-track {
    width: 100%; height: 8px; background: var(--muted); border-radius: 9999px;
    overflow: hidden;
}
.top5-bar-fill {
    height: 100%; border-radius: 9999px;
    transition: width 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Top 5 bar colors — vibrant gradient fills */
.top5-item:nth-child(1) .top5-bar-fill { background: linear-gradient(90deg, #7c3aed, #a78bfa); }
.top5-item:nth-child(2) .top5-bar-fill { background: linear-gradient(90deg, #059669, #34d399); }
.top5-item:nth-child(3) .top5-bar-fill { background: linear-gradient(90deg, #0284c7, #38bdf8); }
.top5-item:nth-child(4) .top5-bar-fill { background: linear-gradient(90deg, #d97706, #fbbf24); }
.top5-item:nth-child(5) .top5-bar-fill { background: linear-gradient(90deg, #e11d48, #fb7185); }

/* ---- Recent Expenses List ---- */
.recent-list {
    display: flex; flex-direction: column; gap: 0;
}
.recent-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 0; border-bottom: 1px solid var(--border);
    transition: all 0.15s ease;
    border-radius: var(--radius-sm);
}
.recent-item:last-child { border-bottom: none; }
.recent-item:hover {
    background: var(--card-hover);
    margin: 0 -20px; padding: 10px 20px;
}
.recent-dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.recent-info { flex: 1; min-width: 0; }
.recent-cat {
    font-size: 0.82rem; font-weight: 600; color: var(--foreground);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recent-date {
    font-size: 0.7rem; color: var(--muted-foreground); font-family: var(--font-mono);
}
.recent-amount {
    font-family: var(--font-mono); font-weight: 700; font-size: 0.85rem;
    color: var(--foreground); white-space: nowrap;
}

/* ---- Tooltip ---- */
.dash-tooltip {
    position: fixed; z-index: 9999;
    background: rgba(9, 9, 11, 0.9);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    color: #fafafa;
    padding: 8px 14px; border-radius: var(--radius-sm);
    font-family: var(--font-sans); font-size: 0.76rem; font-weight: 600;
    pointer-events: none;
    opacity: 0; transition: opacity 0.15s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.dash-tooltip.visible { opacity: 1; }

/* ---- Smart Insights Strip ---- */
.insights-strip {
    margin-bottom: 1.5rem;
    overflow: hidden;
    border-radius: var(--radius);
}
.insights-scroll {
    display: flex; gap: 12px;
    overflow-x: auto; padding: 4px 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.insights-scroll::-webkit-scrollbar { display: none; }
.insight-card {
    flex: 0 0 auto; min-width: 220px; max-width: 280px;
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 18px;
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    transition: all 0.25s ease;
    animation: kpiSlideIn 0.5s ease backwards;
}
.insight-card:hover {
    box-shadow: var(--shadow-md); transform: translateY(-2px);
}
.insight-icon {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 1.1rem;
}
.insight-icon-purple { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }
.insight-icon-green { background: rgba(34, 197, 94, 0.12); color: #22c55e; }
.insight-icon-blue { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.insight-icon-amber { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.insight-icon-rose { background: rgba(244, 63, 94, 0.12); color: #f43f5e; }
.insight-icon-cyan { background: rgba(6, 182, 212, 0.12); color: #06b6d4; }

[data-theme="dark"] .insight-icon-purple { background: rgba(167, 139, 250, 0.15); color: #a78bfa; }
[data-theme="dark"] .insight-icon-green { background: rgba(74, 222, 128, 0.15); color: #4ade80; }
[data-theme="dark"] .insight-icon-blue { background: rgba(96, 165, 250, 0.15); color: #60a5fa; }
[data-theme="dark"] .insight-icon-amber { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
[data-theme="dark"] .insight-icon-rose { background: rgba(251, 113, 133, 0.15); color: #fb7185; }
[data-theme="dark"] .insight-icon-cyan { background: rgba(34, 211, 238, 0.15); color: #22d3ee; }

.insight-body { flex: 1; min-width: 0; }
.insight-label {
    font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px; color: var(--muted-foreground); margin-bottom: 3px;
}
.insight-value {
    font-family: var(--font-mono); font-size: 0.92rem; font-weight: 700;
    color: var(--foreground); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.insight-meta {
    font-size: 0.7rem; color: var(--muted-foreground); margin-top: 2px;
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
    .kpi-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 860px) {
    .chart-grid { grid-template-columns: 1fr; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
    .kpi-row { grid-template-columns: 1fr; }
    .insight-card { min-width: 180px; padding: 12px 14px; }
    .dash-filter-presets { gap: 4px; }
    .dash-preset { padding: 5px 10px; font-size: 0.72rem; }
    .chart-body-pie { flex-direction: column; }
    .chart-body-pie canvas { width: 220px !important; height: 220px !important; }
    .kpi-value { font-size: 1rem; }

    /* Responsive custom filters */
    .dash-filter-custom {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .dash-filter-custom input, .dash-filter-custom select {
        width: 100%;
        box-sizing: border-box;
    }
    .filter-to-label {
        text-align: center;
        margin: 2px 0;
    }
}
