/* Phase 8 — Reports & Dashboards */

.reports-page {
    padding: 1.5rem 0;
    max-width: 1450px;
    margin: 0 auto;
}

.reports-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.reports-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.reports-header h1 i {
    margin-right: 0.5rem;
    color: var(--color-accent-orange);
}

.reports-header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.kpi-card {
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: 0.5rem;
    padding: 0.9rem 1rem;
}

.kpi-card h3 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-strong);
}

.kpi-card p {
    margin: 0.15rem 0 0 0;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Optional change-vs-prior line under a KPI label */
.kpi-card .kpi-delta {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
    gap: 1rem;
}

.chart-card,
.report-card {
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: 0.5rem;
    padding: 1rem 1.2rem;
}

.chart-card h4,
.report-card h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    font-weight: 600;
}

/* Chart.js canvas container — gives the canvas a definite height so
   Chart.js can size correctly with maintainAspectRatio:false */
.chart-canvas-wrap {
    position: relative;
    height: 280px;
    width: 100%;
}

.chart-canvas-wrap > canvas {
    max-width: 100%;
}

/* ------------------------------------------------------------------ */
/* BI-style report shell, scope line, sections and KPI polish          */
/* ------------------------------------------------------------------ */

.report-shell {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.reports-header-titles h1 {
    display: flex;
    align-items: center;
}

.report-subtitle {
    margin: 0.25rem 0 0 0;
    font-size: 0.9rem;
}

/* Scope / filter context line, mirrors a Power BI report header strip */
.report-scope {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.85rem;
    background: var(--tint-info-bg);
    border: 1px solid var(--border-subtle);
    color: var(--tint-info-text);
    border-radius: 2rem;
    font-size: 0.82rem;
    font-weight: 600;
    width: fit-content;
}

.report-scope i {
    font-size: 0.9rem;
}

.report-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Titled visual container (KPIs / charts / tables) */
.report-section {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.report-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    border-bottom: 2px solid var(--border-subtle);
    padding-bottom: 0.5rem;
}

.report-section-head h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.report-section-head h2 i {
    color: var(--text-strong);
    font-size: 1rem;
}

.report-section-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* KPI cards get a left accent + hover lift for a dashboard feel */
.kpi-card {
    border-left: 4px solid var(--color-primary);
    box-shadow: var(--shadow-xs);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

/* Chart cards: soft shadow so the visual grid reads like report tiles */
.chart-card {
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}

.chart-card h4 {
    color: var(--text-strong);
}

/* Wraps a report table so it sits in its own BI tile */
.report-table-card {
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem 1rem;
    box-shadow: var(--shadow-sm);
}

/* Quick Reports button grid — fills the card width */
.quick-reports-card {
    margin-top: 1rem;
}

.quick-reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.6rem;
}

.quick-reports-grid > .btn {
    width: 100%;
    justify-content: center;
}

.report-table-wrap {
    overflow-x: auto;
}

.report-table {
    width: 100%;
    /* auto layout: columns size to their content and wrap at WORD boundaries only.
       fixed + break-anywhere squeezed wide tables (16-col employee directory) into
       equal slivers that clipped headers and broke words mid-letter. A too-wide
       table scrolls inside .report-table-wrap instead. */
    table-layout: auto;
}

/* table.report-table beats the global ".table tbody td" break-anywhere and
   padding rules (components/tables.css) on specificity. Report tables are
   dense data grids — tighter cells than the app's default table style. */
table.report-table thead th,
table.report-table tbody td {
    overflow-wrap: normal;
    word-break: normal;
    padding: 0.55rem 0.75rem;
    font-size: 0.9rem;
}

.report-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface-inset);
    color: var(--text-strong);
    font-weight: 700;
    border-bottom: 2px solid var(--border-strong);
}

.report-filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

@media (max-width: 768px) {
    .report-filters {
        grid-template-columns: 1fr;
    }
}

/* Human Capital filter bar */
.hc-filter-bar {
    margin-bottom: 1rem;
}

.hc-filter-field {
    margin-bottom: 0.75rem;
}

.hc-filter-field label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.hc-filter-field .form-control {
    width: 100%;
}

.hc-filter-actions {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    margin-bottom: 0.75rem;
}

.report-summary-line {
    margin: 0.25rem 0 0.75rem;
    color: var(--text-muted);
}

.report-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.report-table th.sortable i {
    margin-left: 0.25rem;
    font-size: 0.7rem;
}

/* Custom report builder column picker */
.builder-columns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 0.35rem 1rem;
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: 0.5rem;
    padding: 0.9rem 1rem;
}

/* EEA2 workforce-profile table: many narrow numeric columns */
.ee-profile-table {
    table-layout: auto;
    font-variant-numeric: tabular-nums;
}

.ee-profile-table .ee-level-col {
    min-width: 220px;
}

.ee-profile-table td,
.ee-profile-table th {
    white-space: nowrap;
}

.ee-profile-table td:first-child {
    white-space: normal;
    max-width: 340px;
}

.ee-profile-table tfoot td {
    background: var(--surface-raised);
    border-top: 2px solid var(--border-strong);
}

/* Excel/PDF export action cluster in report headers */
.export-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* ------------------------------------------------------------------ */
/* Chart card header + expand affordance                               */
/* ------------------------------------------------------------------ */

.chart-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.chart-card-head h4 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-strong);
}

.chart-expand-btn {
    border: none;
    background: transparent;
    color: var(--text-faint);
    padding: 0.15rem 0.3rem;
    border-radius: 0.35rem;
    line-height: 1;
    transition: color 0.15s ease, background 0.15s ease;
}

.chart-expand-btn:hover {
    color: var(--text-strong);
    background: var(--surface-hover);
}

.chart-canvas-clickable {
    cursor: zoom-in;
}

/* ------------------------------------------------------------------ */
/* Fullscreen chart modal                                              */
/* ------------------------------------------------------------------ */

body.hc-modal-open {
    overflow: hidden;
}

.chart-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 18, 28, 0.60); /* dark scrim — intentional in both themes */
    backdrop-filter: blur(2px);
    z-index: 1055;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    animation: hc-fade-in 0.15s ease;
}

@media (max-width: 600px) {
    .chart-modal-backdrop {
        padding: 1rem;
    }
}

.chart-modal {
    background: var(--surface-card);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-xl);
    width: min(1200px, 100%);
    max-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: hc-scale-in 0.15s ease;
}

.chart-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
}

.chart-modal-head h3 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-strong);
}

.chart-modal-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-modal-close {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.35rem;
    line-height: 1;
}

.chart-modal-close:hover {
    color: var(--text-strong);
    background: var(--surface-hover);
}

.chart-modal-body {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(260px, 2fr);
    gap: 1.25rem;
    padding: 1.25rem;
    overflow: auto;
}

.chart-modal-canvas-wrap {
    position: relative;
    height: clamp(320px, 60vh, 560px);
    min-width: 0;
}

.chart-modal-table-wrap {
    overflow: auto;
    max-height: clamp(320px, 60vh, 560px);
    border: 1px solid var(--border-subtle);
    border-radius: 0.5rem;
}

.chart-modal-table {
    margin: 0;
    table-layout: auto;
}

.chart-modal-table tfoot td {
    background: var(--surface-raised);
    border-top: 2px solid var(--border-strong);
}

@media (max-width: 900px) {
    .chart-modal-body {
        grid-template-columns: 1fr;
    }
}

@keyframes hc-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes hc-scale-in {
    from { transform: scale(0.97); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ------------------------------------------------------------------ */
/* Loading skeletons + empty states                                    */
/* ------------------------------------------------------------------ */

.report-loading {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--surface-inset);
    border-radius: 0.5rem;
}

.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, var(--surface-card-translucent), transparent);
    animation: hc-shimmer 1.4s infinite;
}

.skeleton-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
}

.skeleton-kpi {
    height: 72px;
}

.skeleton-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1rem;
}

.skeleton-chart {
    height: 280px;
}

@keyframes hc-shimmer {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

.report-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    text-align: center;
}

.report-empty-state i {
    font-size: 2rem;
    color: var(--text-faint);
}

.report-empty-state p {
    margin: 0;
}
