/* Reports module — light styles aligned with dashboard cards */

.reports-page {
    --reports-gap: var(--space-5, 1.25rem);
    /* Match Index filters-bar controls (.filter-select / .filter-search input). */
    --reports-filter-control-height: 42px;
    --reports-filter-field-min: 11rem;
    --reports-filter-field-max: 15rem;
    --reports-filter-lookup-min: 14rem;
    --reports-filter-lookup-max: 18rem;
}

/*
 * Each labeled filter is an independent flex item.
 * Gaps (not absolute positioning) separate controls when they wrap.
 * overflow:visible keeps native select/date popups from being clipped by the bar.
 */
.reports-filters-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3, 0.75rem);
    row-gap: var(--space-3, 0.75rem);
    column-gap: var(--space-3, 0.75rem);
    overflow: visible;
    position: relative;
    z-index: 2;
}

.reports-filter-field {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    flex: 1 1 var(--reports-filter-field-min);
    min-width: 0;
    max-width: var(--reports-filter-field-max);
    width: auto;
    align-self: flex-end;
    position: relative;
    z-index: 1;
    box-sizing: border-box;
}

.reports-filter-field--lookup {
    flex: 1 1 var(--reports-filter-lookup-min);
    max-width: var(--reports-filter-lookup-max);
}

.reports-filter-field .dash-filter-label {
    line-height: 1.25;
    white-space: normal;
    overflow-wrap: anywhere;
    margin: 0;
}

/*
 * Neutralize responsive.css `.filters-bar .filter-field { flex: 1 1 12rem }`
 * which treated 12rem as HEIGHT inside column wrappers.
 * Controls fill their field slot only — never spill into neighbors.
 */
.reports-filters-bar .reports-filter-field .filter-field,
.reports-filters-bar .reports-filter-field input.form-control,
.reports-filters-bar .reports-filter-field .form-control.filter-field,
.reports-filters-bar .reports-filter-field .filter-select {
    flex: 0 0 auto;
    flex-grow: 0;
    flex-shrink: 0;
    flex-basis: auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: var(--reports-filter-control-height);
    min-height: var(--reports-filter-control-height);
    max-height: var(--reports-filter-control-height);
    box-sizing: border-box;
}

.reports-filters-bar .reports-filter-field .filter-field,
.reports-filters-bar .reports-filter-field input.form-control,
.reports-filters-bar .reports-filter-field .form-control.filter-field {
    padding-top: 0;
    padding-bottom: 0;
    line-height: calc(var(--reports-filter-control-height) - 2px);
}

.reports-filters-bar .reports-filter-field .filter-select {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reports-filter-actions {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
    align-self: flex-end;
    position: relative;
    z-index: 1;
}

/*
 * Lookup: search + select stacked in ONE labeled slot (not side-by-side).
 * Side-by-side previously overflowed max-width:16rem into neighboring filters.
 */
.reports-filters-bar .reports-lookup-filter {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: auto;
}

.reports-filters-bar .reports-lookup-filter .filter-field,
.reports-filters-bar .reports-lookup-filter input.form-control,
.reports-filters-bar .reports-lookup-filter .filter-select {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: var(--reports-filter-control-height);
    min-height: var(--reports-filter-control-height);
    max-height: var(--reports-filter-control-height);
}

/* Extra filters participate as siblings of Period/Dates/Search (independent slots). */
.reports-extra-filters.d-contents {
    display: contents;
}

.reports-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--reports-gap);
    margin-bottom: var(--space-6, 1.5rem);
}

.reports-kpi-card {
    border: 1px solid var(--surface-border, #e5e7eb);
    border-radius: var(--radius-md, 10px);
    background: var(--surface-card, #fff);
    padding: 1rem 1.1rem;
    min-height: 96px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.reports-kpi-card.is-unsupported {
    opacity: 0.85;
    background: #fafafa;
}

.reports-kpi-label {
    font-size: var(--fs-sm, 0.85rem);
    color: var(--text-muted, #6b7280);
    font-weight: 600;
}

.reports-kpi-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary, #111827);
    line-height: 1.2;
}

.reports-kpi-change {
    font-size: var(--fs-xs, 0.75rem);
    color: var(--text-secondary, #64748b);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    line-height: 1.35;
}

.reports-kpi-change__value {
    font-weight: 600;
    white-space: nowrap;
}

.reports-kpi-change__basis {
    color: var(--text-muted, #6b7280);
    font-weight: 500;
}

.reports-kpi-change.is-up .reports-kpi-change__value {
    color: #198754;
}

.reports-kpi-change.is-down .reports-kpi-change__value {
    color: #dc3545;
}

.reports-kpi-change.is-up {
    color: var(--text-secondary, #64748b);
}

.reports-kpi-change.is-down {
    color: var(--text-secondary, #64748b);
}

.reports-kpi-na {
    color: #9ca3af;
    font-weight: 600;
    cursor: help;
}

.reports-charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--reports-gap);
    margin-bottom: var(--space-6, 1.5rem);
}

.reports-chart-card {
    border: 1px solid var(--surface-border, #e5e7eb);
    border-radius: var(--radius-md, 10px);
    background: var(--surface-card, #fff);
    padding: 1rem;
}

.reports-chart-title {
    font-size: var(--fs-sm, 0.85rem);
    font-weight: 600;
    margin: 0 0 0.75rem;
    color: var(--text-secondary, #64748b);
}

.reports-chart-wrap {
    position: relative;
    height: 260px;
}

.reports-limitations {
    margin-bottom: 1rem;
}

.reports-limitations ul {
    margin: 0.35rem 0 0;
    padding-inline-start: 1.2rem;
}

.reports-meta {
    font-size: var(--fs-sm, 0.85rem);
}

.reports-links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.85rem;
}

.reports-link-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--surface-border, #e5e7eb);
    border-radius: var(--radius-md, 10px);
    background: var(--surface-card, #fff);
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.reports-link-card:hover {
    border-color: rgba(27, 111, 168, 0.45);
    box-shadow: 0 0 0 2px rgba(27, 111, 168, 0.12);
    color: inherit;
}

.reports-link-card i {
    font-size: 1.25rem;
    color: var(--primary, #1b6fa8);
    margin-top: 0.15rem;
}

.reports-link-card strong {
    display: block;
    font-size: 0.95rem;
}

.reports-link-card span {
    display: block;
    font-size: var(--fs-xs, 0.75rem);
    color: var(--text-muted, #6b7280);
    margin-top: 0.2rem;
}

.reports-table-card .content-card-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--surface-border, #e5e7eb);
}

/* Overview Top Products only — avoid affecting multi-column report tables */
#reportsOverviewPage .reports-table-card .data-table {
    table-layout: fixed;
    width: 100%;
}

#reportsOverviewPage .reports-table-card .data-table th:nth-child(1),
#reportsOverviewPage .reports-table-card .data-table td:nth-child(1) {
    width: 18%;
}

#reportsOverviewPage .reports-table-card .data-table th:nth-child(2),
#reportsOverviewPage .reports-table-card .data-table td.reports-product-name {
    width: 46%;
}

#reportsOverviewPage .reports-table-card .data-table th:nth-child(3),
#reportsOverviewPage .reports-table-card .data-table th:nth-child(4),
#reportsOverviewPage .reports-table-card .data-table td.reports-col-metric {
    width: 18%;
    white-space: nowrap;
    vertical-align: middle;
}

.reports-product-name {
    min-width: 0;
    vertical-align: middle;
}

.reports-product-name__text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.35;
    max-height: calc(1.35em * 2);
}

/*
 * Product Performance table: products.css applies white-space:nowrap to ALL
 * .products-table-wrap cells. With many qty/revenue columns, long product names
 * expand into Quantity Sold. Keep name clamp + independent metric min-widths,
 * and let the wrapper scroll horizontally (not the page).
 */
#reportPage[data-report-key="products"] .products-table-wrap,
.reports-page[data-report-key="products"] .products-table-wrap {
    overflow-x: auto;
    max-width: 100%;
}

#reportPage[data-report-key="products"] .products-table-wrap .data-table,
.reports-page[data-report-key="products"] .products-table-wrap .data-table {
    /* SKU + name + 10 metric columns need room; do not squeeze into 100% viewport. */
    min-width: 1720px;
    width: max(100%, 1720px);
    table-layout: auto;
}

#reportPage[data-report-key="products"] .products-table-wrap .data-table th.reports-product-name,
#reportPage[data-report-key="products"] .products-table-wrap .data-table td.reports-product-name,
.reports-page[data-report-key="products"] .products-table-wrap .data-table th.reports-product-name,
.reports-page[data-report-key="products"] .products-table-wrap .data-table td.reports-product-name {
    white-space: normal;
    min-width: 14rem;
    max-width: 22rem;
    width: 16rem;
    vertical-align: middle;
}

#reportPage[data-report-key="products"] .products-table-wrap .data-table th.reports-col-metric,
#reportPage[data-report-key="products"] .products-table-wrap .data-table td.reports-col-metric,
.reports-page[data-report-key="products"] .products-table-wrap .data-table th.reports-col-metric,
.reports-page[data-report-key="products"] .products-table-wrap .data-table td.reports-col-metric {
    min-width: 7.75rem;
    max-width: 11rem;
    vertical-align: middle;
    text-align: end;
}

#reportPage[data-report-key="products"] .products-table-wrap .data-table td.reports-col-metric,
.reports-page[data-report-key="products"] .products-table-wrap .data-table td.reports-col-metric {
    white-space: nowrap;
}

#reportPage[data-report-key="products"] .products-table-wrap .data-table th.reports-col-metric,
.reports-page[data-report-key="products"] .products-table-wrap .data-table th.reports-col-metric {
    white-space: normal;
    line-height: 1.25;
    text-transform: none;
    letter-spacing: 0;
}

/* Report tables reuse products-table-wrap but have no Actions column — disable sticky last cell. */
.reports-page .products-table-wrap .data-table th:last-child,
.reports-page .products-table-wrap .data-table td:last-child {
    position: static;
    inset-inline-end: auto;
    box-shadow: none;
    background: inherit;
}

.reports-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted, #6b7280);
}

.reports-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--text-secondary, #64748b);
}

@media (max-width: 768px) {
    .reports-chart-wrap {
        height: 220px;
    }

    .reports-filters-bar > .reports-filter-field,
    .reports-filters-bar .reports-filter-field--lookup,
    .reports-filters-bar .reports-filter-actions {
        flex: 1 1 100%;
        max-width: none;
        width: 100%;
        min-width: 0;
        align-self: stretch;
    }

    .reports-filters-bar .reports-filter-field .filter-field,
    .reports-filters-bar .reports-filter-field input.form-control,
    .reports-filters-bar .reports-filter-field .form-control.filter-field,
    .reports-filters-bar .reports-filter-field .filter-select,
    .reports-filters-bar .reports-lookup-filter .filter-field,
    .reports-filters-bar .reports-lookup-filter input.form-control,
    .reports-filters-bar .reports-lookup-filter .filter-select {
        flex: 0 0 auto;
        flex-basis: auto;
        width: 100%;
        max-width: none;
        min-width: 0;
        height: var(--reports-filter-control-height);
        min-height: var(--reports-filter-control-height);
        max-height: var(--reports-filter-control-height);
    }

    .reports-filters-bar .reports-lookup-filter {
        width: 100%;
        max-width: none;
    }

    .reports-filter-actions {
        padding-top: 0.15rem;
        justify-content: stretch;
    }

    .reports-filter-actions .btn-primary-custom,
    .reports-filter-actions .btn-secondary-custom {
        flex: 1 1 auto;
        height: var(--reports-filter-control-height);
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .reports-filter-field {
        flex: 1 1 calc(50% - var(--space-3, 0.75rem));
        max-width: calc(50% - var(--space-3, 0.75rem));
    }

    .reports-filter-field--lookup {
        flex: 1 1 calc(50% - var(--space-3, 0.75rem));
        max-width: calc(50% - var(--space-3, 0.75rem));
    }
}
