/* ═══════════════════════════════════════════════════════
   FA Dashboard — Custom Styles
   Dark theme, glassmorphism, drill-down, print-ready
   ═══════════════════════════════════════════════════════ */

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0c1322; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ─── KPI Cards ─── */
.kpi-card {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.7), rgba(15, 23, 42, 0.9));
    border: 1px solid rgba(51, 65, 85, 0.5);
    border-radius: 16px;
    padding: 1.25rem 1.5rem;
    backdrop-filter: blur(12px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}
.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(16, 185, 129, 0.4), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}
.kpi-card:hover { border-color: rgba(16, 185, 129, 0.3); transform: translateY(-2px); box-shadow: 0 8px 32px rgba(0,0,0,0.3); }
.kpi-card:hover::before { opacity: 1; }
.kpi-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 0.75rem; }
.kpi-value { font-size: 1.75rem; font-weight: 800; color: #f1f5f9; letter-spacing: -0.02em; line-height: 1.1; margin-bottom: 0.25rem; }
.kpi-label { font-size: 0.75rem; color: #94a3b8; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }

/* ─── Chart Cards ─── */
.chart-card {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.6), rgba(15, 23, 42, 0.85));
    border: 1px solid rgba(51, 65, 85, 0.4);
    border-radius: 16px;
    overflow: hidden;
    transition: border-color 0.3s;
}
.chart-card:hover { border-color: rgba(51, 65, 85, 0.7); }
.chart-header { padding: 1.25rem 1.5rem 0; display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.chart-title { font-size: 0.95rem; font-weight: 700; color: #e2e8f0; }
.chart-subtitle { font-size: 0.7rem; color: #64748b; font-weight: 400; }
.chart-body { padding: 1rem 1.5rem 1.5rem; height: 320px; position: relative; }
.chart-body-donut { display: flex; align-items: center; justify-content: center; }
.chart-body-wide { height: 380px; }

/* ─── Print/Report Buttons ─── */
.print-btn {
    font-size: 0.7rem;
    color: #94a3b8;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(51, 65, 85, 0.5);
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.print-btn:hover { color: #e2e8f0; border-color: rgba(16, 185, 129, 0.4); background: rgba(16, 185, 129, 0.1); }

/* ─── Aging Summary ─── */
.aging-total { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; }
.aging-total .amount { font-size: 1.25rem; font-weight: 800; color: #f1f5f9; display: block; }
.aging-total .label { font-size: 0.65rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.08em; }

/* ─── Top Parties Table ─── */
.parties-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.parties-table thead th {
    padding: 0.75rem 1rem; font-size: 0.7rem; font-weight: 600; color: #94a3b8;
    text-transform: uppercase; letter-spacing: 0.05em;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5); background: rgba(15, 23, 42, 0.5);
}
.parties-table tbody tr { border-bottom: 1px solid rgba(51, 65, 85, 0.2); transition: background 0.15s; cursor: pointer; }
.parties-table tbody tr:hover { background: rgba(30, 41, 59, 0.5); }
.parties-table tbody td { padding: 0.6rem 1rem; color: #cbd5e1; white-space: nowrap; }
.parties-table .amount-bar { height: 6px; border-radius: 3px; background: linear-gradient(90deg, #10b981, #06b6d4); transition: width 0.6s ease-out; }
.parties-table .amount-bar-neg { background: linear-gradient(90deg, #f43f5e, #f97316); }

/* ─── Drill-Down Table ─── */
.drill-table { border-collapse: collapse; font-size: 0.78rem; }
.drill-table thead th {
    padding: 0.5rem 0.75rem; font-size: 0.68rem; font-weight: 600; color: #94a3b8;
    text-transform: uppercase; border-bottom: 1px solid #334155;
    position: sticky; top: 0; background: #0f172a; cursor: pointer;
    white-space: nowrap; user-select: none;
}
.drill-table thead th:hover { color: #10b981; }
.drill-table thead th.sorted-asc::after { content: ' ↑'; color: #10b981; }
.drill-table thead th.sorted-desc::after { content: ' ↓'; color: #10b981; }
.drill-table tbody td { padding: 0.4rem 0.75rem; border-bottom: 1px solid rgba(51, 65, 85, 0.15); white-space: nowrap; }
.drill-table tbody tr:hover { background: rgba(30, 41, 59, 0.4); }

/* ─── Report Table (light theme for printing) ─── */
.report-table { border-collapse: collapse; font-size: 0.8rem; }
.report-table thead th {
    padding: 0.6rem 0.75rem; font-size: 0.7rem; font-weight: 600; color: #374151;
    text-transform: uppercase; border-bottom: 2px solid #e5e7eb;
    position: sticky; top: 0; background: #fff; cursor: pointer;
    white-space: nowrap; user-select: none;
}
.report-table thead th:hover { color: #059669; }
.report-table thead th.sorted-asc::after { content: ' ↑'; color: #059669; }
.report-table thead th.sorted-desc::after { content: ' ↓'; color: #059669; }
.report-table tbody td { padding: 0.45rem 0.75rem; border-bottom: 1px solid #f3f4f6; color: #1f2937; white-space: nowrap; }
.report-table tbody tr:hover { background: #f0fdf4; }
.report-table tbody tr:nth-child(even) { background: #f9fafb; }
.report-table tbody tr:nth-child(even):hover { background: #f0fdf4; }

/* ─── Animations ─── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
.kpi-card, .chart-card { animation: fadeInUp 0.5s ease-out both; }
.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; }

/* ─── Print Styles ─── */
@media print {
    body { background: white !important; color: black !important; }
    #loginGate, #dashboardApp, #drillPanel, .no-print { display: none !important; }
    #reportModal { position: static !important; display: block !important; }
    #reportModal > div:first-child { display: none !important; } /* overlay */
    #reportModal > div:last-child {
        position: static !important; inset: 0 !important;
        border-radius: 0 !important; box-shadow: none !important;
        max-height: none !important; overflow: visible !important;
    }
    .report-table { font-size: 8pt !important; }
    .report-table thead th { background: #f3f4f6 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .report-table tbody tr:nth-child(even) { background: #f9fafb !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .print-header { page-break-after: avoid; }
    .print-footer { page-break-before: avoid; }
    @page { margin: 1cm; size: landscape; }
}

/* ─── Responsive ─── */
@media (max-width: 640px) {
    .kpi-value { font-size: 1.35rem; }
    .chart-body { height: 260px; padding: 0.75rem 1rem 1rem; }
    .chart-header { padding: 1rem 1rem 0; }
}
