/* Excel-style report designer. Shared record filters and exports stay intact. */
#custom-reports-view .pivot-designer-workspace [hidden],
#custom-reports-view .pivot-scope-card [hidden] { display: none !important; }
#custom-reports-view .pivot-scope-card { padding: 0; margin-bottom: 18px; }
.pivot-scope-card > details > summary { display: flex; gap: 18px; align-items: center; padding: 16px 20px; list-style: none; cursor: pointer; }
.pivot-scope-card > details > summary::-webkit-details-marker { display: none; }
.pivot-scope-card > details > summary strong { display: flex; align-items: center; gap: 9px; color: var(--text-main); font-size: 14px; white-space: nowrap; }
.pivot-scope-card > details > summary > span { color: var(--text-muted); font-size: 13px; flex: 1; }
.pivot-scope-card > details > summary > i { font-size: 11px; transition: transform .15s; }
.pivot-scope-card > details[open] > summary > i { transform: rotate(180deg); }
.pivot-scope-body { padding: 4px 20px 20px; }
.pivot-scope-body .report-step { display: none; }
#custom-reports-view .pivot-designer-workspace > .report-builder-card { padding: 20px; overflow: visible; }
.pivot-designer-workspace .report-builder-heading { margin-bottom: 18px; }
.pivot-designer-workspace .report-builder-heading .card-title { font-size: 18px; }
.pivot-designer-workspace .report-example-btn { padding: 7px 11px; font-size: 12px; }
.pivot-designer { display: grid; grid-template-columns: 252px minmax(0, 1fr); gap: 22px; align-items: start; }
.pivot-palette { border: 1px solid var(--border-color); border-radius: 10px; padding: 14px 10px 10px; background: var(--bg-card, #fff); position: sticky; top: 16px; min-width: 0; }
.pivot-palette-heading { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 12px; }
.pivot-palette-heading h3 { margin: 0; font-size: 14px; font-weight: 700; }
.pivot-palette-heading > span { font-size: 11px; color: var(--text-muted); border: 1px solid var(--border-color); border-radius: 5px; padding: 1px 6px; }
.pivot-search { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border-color); border-radius: 7px; }
.pivot-search > i { font-size: 12px; color: var(--text-muted); }
.pivot-search input { border: 0; outline: none; background: transparent; min-width: 0; width: 100%; font: inherit; font-size: 13px; color: var(--text-main); }
.pivot-search:focus-within { outline: 2px solid var(--accent-primary, #2563eb); outline-offset: 2px; }
.pivot-palette-hint { margin: 10px 4px; font-size: 11.5px; line-height: 1.55; color: var(--text-muted); }
.pivot-field-list { max-height: min(620px, 66vh); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.pivot-palette-group h4 { margin: 0; padding: 10px 7px 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); position: sticky; top: 0; background: var(--bg-card, #fff); z-index: 1; }
.pivot-palette-field { display: flex; align-items: center; gap: 8px; width: 100%; border: 1px solid transparent; border-radius: 6px; background: none; text-align: left; padding: 8px 6px; color: var(--text-main); cursor: grab; font: inherit; font-size: 12.5px; line-height: 1.35; }
.pivot-palette-field > span { flex: 1; min-width: 0; }
.pivot-palette-field > i:not(.pivot-drag-handle) { width: 12px; font-size: 11px; color: var(--text-muted); }
.pivot-palette-field .pivot-field-plus { opacity: 0; }
.pivot-palette-field small { display: block; font-size: 10px; color: var(--accent-primary, #2563eb); margin-top: 3px; }
.pivot-palette-field:hover, .pivot-palette-field.is-selected { background: rgba(37, 99, 235, .065); border-color: rgba(37, 99, 235, .15); }
.pivot-palette-field:hover .pivot-field-plus, .pivot-palette-field:focus-visible .pivot-field-plus { opacity: 1; }
.pivot-drag-handle { color: var(--text-muted, #94a3b8); font-size: 10px; flex: 0 0 auto; }
.pivot-canvas { min-width: 0; }
.pivot-designer-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0 0 12px; }
.pivot-designer-toolbar > span { font-size: 13px; color: var(--text-muted); }
.pivot-designer-toolbar > div { display: flex; gap: 8px; }
.pivot-designer .btn { font-size: 12px; padding: 7px 10px; min-height: 32px; }
.pivot-wells { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pivot-well { border: 1px solid var(--border-color); border-radius: 9px; min-height: 138px; padding: 11px; background: rgba(148, 163, 184, .035); transition: border-color .12s, background .12s; }
.pivot-well-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.pivot-well-heading h3 { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; margin: 0; }
.pivot-well-heading h3 i { color: var(--text-muted); font-size: 11px; }
.pivot-well-heading > span { font-size: 10px; color: var(--text-muted); }
.pivot-well-values h3 i { color: #0f766e; }
.pivot-well-rows h3 i { color: #2563eb; }
.pivot-well-columns h3 i { color: #7c3aed; }
.pivot-well-chips { display: flex; flex-direction: column; gap: 6px; min-height: 42px; }
.pivot-drop-hint { font-size: 11.5px; line-height: 1.5; color: var(--text-muted); padding: 7px 0; }
.pivot-add-field { border: 0; background: none; color: var(--accent-primary, #2563eb); font: inherit; font-size: 11px; padding: 7px 2px 1px; cursor: pointer; }
.pivot-add-field i { font-size: 9px; margin-right: 4px; }
.pivot-chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-card, #fff); padding: 0 7px; min-height: 37px; cursor: grab; }
.pivot-chip-options { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; padding: 8px 0; border: 0; background: none; color: var(--text-main); text-align: left; font: inherit; font-size: 12px; line-height: 1.35; cursor: pointer; }
.pivot-chip-options > span { min-width: 0; overflow-wrap: anywhere; }
.pivot-chip-options small { display: block; font-size: 10.5px; color: var(--text-muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px; }
.pivot-chip-options > i { font-size: 8px; color: var(--text-muted); }
.pivot-chip-remove, .pivot-icon-button { width: 25px; height: 25px; border: 0; border-radius: 4px; background: transparent; color: var(--text-muted); cursor: pointer; flex: 0 0 auto; }
.pivot-chip-remove:hover, .pivot-icon-button:hover { background: rgba(148,163,184,.16); color: var(--text-main); }
.pivot-well.can-drop { border-color: rgba(37,99,235,.5); border-style: dashed; }
.pivot-well.is-drag-over { background: rgba(37,99,235,.08); border-color: #2563eb; }
.pivot-chip.pivot-drop-before { border-top: 3px solid #2563eb; }
.pivot-designer-status { font-size: 11px; color: var(--text-muted); min-height: 17px; margin: 10px 1px 12px; }
.pivot-field-placement { position: sticky; bottom: 0; padding: 12px 8px 4px; border-top: 1px solid var(--border-color); margin-top: 10px; background: var(--bg-card, #fff); }
.pivot-field-placement > strong, .pivot-field-placement > label { display: block; padding-right: 18px; font-size: 12px; margin-bottom: 7px; }
.pivot-field-placement > span { font-size: 10px; color: var(--text-muted); }
.pivot-field-placement > div { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.pivot-field-placement .form-select { width: 100%; min-width: 0; margin-bottom: 8px; font-size: 12px; }
.pivot-placement-close { position: absolute; right: 1px; top: 7px; width: 24px; height: 24px; border: 0; background: none; color: var(--text-muted); cursor: pointer; }
.pivot-options-panel { padding: 14px; margin: 12px 0; border: 1px solid rgba(37,99,235,.35); border-radius: 8px; background: var(--bg-card, #fff); display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.pivot-options-heading { display: flex; justify-content: space-between; align-items: center; flex-basis: 100%; font-size: 13px; }
.pivot-options-panel label { display: grid; gap: 5px; font-size: 11px; color: var(--text-muted); }
.pivot-options-panel .form-select { font-size: 12px; padding: 7px 25px 7px 9px; }
.pivot-options-panel p { font-size: 11px; color: var(--text-muted); margin: 0; flex-basis: 100%; }
.pivot-option-actions { display: flex; gap: 6px; }
.pivot-filter-settings { border: 1px solid var(--border-color); border-radius: 8px; margin-bottom: 14px; }
.pivot-filter-settings > summary { cursor: pointer; padding: 10px 13px; font-size: 12px; font-weight: 600; }
.pivot-filter-settings .custom-report-any-filter-builder { margin: 0; border: 0; border-top: 1px solid var(--border-color); border-radius: 0; padding: 14px; }
.pivot-filter-settings .custom-report-any-filter-header > div:first-child, .pivot-filter-settings .custom-report-filter-quick-add { display: none; }
.pivot-filter-settings .custom-report-add-filter-controls { width: 100%; }
.pivot-filter-settings .custom-report-filter-rule { grid-template-columns: minmax(110px, 1fr) minmax(100px, .8fr) minmax(120px, 1.2fr) 28px; padding: 10px; gap: 10px; }
.pivot-filter-settings .custom-report-filter-control small { font-size: 10px; }
.pivot-filter-settings .form-select, .pivot-filter-settings .form-input { font-size: 12px; min-height: 34px; padding: 7px 9px; }
#custom-reports-view .pivot-canvas .custom-report-actions { margin: 14px 0; padding: 0; justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
#custom-reports-view .pivot-canvas .custom-report-actions .btn { padding: 9px 13px; font-size: 12px; }
#custom-reports-view .pivot-canvas .custom-pivot-result-card { box-shadow: none; border: 1px solid var(--border-color); padding: 0; overflow: hidden; border-radius: 9px; margin: 0; }
.pivot-canvas .custom-pivot-result-header { padding: 18px; margin: 0; gap: 12px; }
.pivot-canvas #custom-pivot-title { font-size: 16px; line-height: 1.45; }
.pivot-canvas #custom-pivot-subtitle { font-size: 11.5px; }
.pivot-canvas .custom-pivot-kpis { gap: 14px; }
.pivot-canvas .custom-pivot-kpis span { font-size: 19px; }
.pivot-canvas .custom-pivot-kpis small { font-size: 10px; }
.pivot-canvas .custom-pivot-warning { font-size: 11.5px; margin: 0 14px 14px; padding: 10px; }
.pivot-canvas .custom-pivot-table-wrap { margin: 0; border-radius: 0; border: 0; max-height: 620px; overflow: auto; }
.pivot-canvas .custom-pivot-table { width: 100%; font-size: 12px; border-collapse: separate; border-spacing: 0; }
.pivot-canvas .custom-pivot-table th, .pivot-canvas .custom-pivot-table td { padding: 10px 13px; border-bottom: 1px solid var(--border-color); border-right: 1px solid rgba(148,163,184,.13); }
.pivot-canvas .custom-pivot-table thead th { background: var(--bg-modal, #f1f5f9); color: var(--text-main); font-size: 11px; letter-spacing: 0; text-transform: none; text-align: right; vertical-align: bottom; position: sticky; top: 0; z-index: 2; white-space: normal; min-width: 105px; }
.pivot-canvas .custom-pivot-table thead th:first-child { text-align: left; min-width: 130px; }
.pivot-canvas .custom-pivot-table thead small { display: block; font-size: 10px; font-weight: 500; margin-top: 4px; color: var(--text-muted); }
.pivot-canvas .custom-pivot-table tbody th { text-align: left; font-weight: 500; white-space: nowrap; background: var(--bg-card, #fff); }
.pivot-canvas .custom-pivot-table tbody td { text-align: right; font-variant-numeric: tabular-nums; background: rgba(37,99,235,var(--pivot-heat,0)); }
.pivot-canvas .custom-pivot-table .pivot-total-cell, .pivot-canvas .custom-pivot-table tfoot td, .pivot-canvas .custom-pivot-table tfoot th { background: rgba(37,99,235,.07); color: var(--text-main); font-weight: 700; }
.pivot-canvas .custom-pivot-table tfoot th { text-align: left; }
.pivot-canvas .custom-pivot-table tfoot td { text-align: right; }
.pivot-canvas .custom-pivot-table .pivot-no-records { text-align: center; padding: 35px; color: var(--text-muted); }
/* Header, frozen labels and their intersection have separate layers. Opaque
   backgrounds keep scrolled values from showing through the frozen edge. */
.pivot-canvas .custom-pivot-table-wrap { isolation: isolate; }
.pivot-canvas .custom-pivot-table thead th { z-index: 4; }
.pivot-canvas .custom-pivot-table thead .pivot-row-label-header { text-align: left; }
.pivot-canvas .custom-pivot-table thead th:first-child { position: sticky; top: 0; left: 0; z-index: 6; background: var(--bg-table-header-sticky, var(--bg-modal, #fff)); }
.pivot-canvas .custom-pivot-table tbody th { position: static; top: auto; z-index: auto; }
.pivot-canvas .custom-pivot-table tbody th:first-child { position: sticky; left: 0; top: auto; z-index: 2; background: var(--bg-modal, #fff); box-shadow: 1px 0 0 var(--border-color); }
.pivot-canvas .custom-pivot-table tbody .pivot-no-records { position: static; z-index: auto; }
.pivot-canvas .custom-pivot-table tfoot th:first-child { position: sticky; left: 0; z-index: 3; background: var(--bg-table-header-sticky, var(--bg-modal, #fff)); box-shadow: 1px 0 0 var(--border-color); }
.pivot-sort-heading { display: flex; justify-content: flex-end; align-items: center; gap: 9px; width: 100%; border: 0; padding: 0; background: none; color: inherit; font: inherit; text-align: inherit; cursor: pointer; }
.pivot-sort-heading > span { flex: 1; }
.pivot-sort-heading > i { font-size: 10px; flex: 0 0 auto; opacity: .55; }
.pivot-sort-heading:hover > i, th[aria-sort="ascending"] .pivot-sort-heading > i, th[aria-sort="descending"] .pivot-sort-heading > i { opacity: 1; color: var(--primary); }
.pivot-sort-heading:disabled { cursor: progress; }
.pivot-sort-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border-top: 1px solid var(--border-color); padding: 11px 14px; }
.pivot-sort-bar > label { font-size: 12px; color: var(--text-muted); }
.pivot-sort-bar .form-select { padding: 6px 26px 6px 9px; font-size: 11.5px; min-height: 32px; width: auto; }
#pivot-sort-field { max-width: min(420px, 65%); }
#pivot-sort-status { flex-basis: 100%; font-size: 10.5px; color: var(--text-muted); line-height: 1.5; }
.pivot-chart-disclosure { border-top: 1px solid var(--border-color); padding: 13px 18px; }
.pivot-chart-disclosure > summary { font-size: 12px; font-weight: 600; cursor: pointer; }
#pivot-chart-value-label { display: flex; align-items: center; gap: 8px; margin: 15px 0; font-size: 12px; }
#pivot-chart-value { width: auto; max-width: 100%; font-size: 12px; }
.pivot-chart-disclosure .custom-pivot-chart-wrap { margin-top: 18px; }
.pivot-designer button:focus-visible, .pivot-designer select:focus-visible, .pivot-scope-card summary:focus-visible { outline: 2px solid var(--accent-primary, #2563eb); outline-offset: 2px; }
@media (max-width: 1150px) {
    .pivot-designer { grid-template-columns: 220px minmax(0,1fr); gap: 14px; }
    .pivot-canvas .custom-pivot-result-header { flex-direction: column; align-items: stretch; }
    .pivot-filter-settings .custom-report-filter-rule { grid-template-columns: minmax(0, 1fr) minmax(0,1fr) 28px; }
    .pivot-filter-settings .custom-report-filter-control:nth-child(3) { grid-column: 1 / 3; }
    .pivot-filter-settings .custom-report-filter-remove { grid-column: 3; grid-row: 1; }
}
@media (max-width: 850px) {
    .pivot-designer { grid-template-columns: 1fr; }
    .pivot-palette { position: static; }
    .pivot-field-list { max-height: 210px; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
    .pivot-palette-hint { margin-bottom: 4px; }
    .pivot-field-placement > div { grid-template-columns: repeat(4,minmax(0,1fr)); }
    .pivot-field-placement { position: relative; }
    .pivot-palette-group h4 { position: static; }
    .pivot-scope-card > details > summary { flex-wrap: wrap; gap: 8px; }
    .pivot-scope-card > details > summary > span { order: 3; flex-basis: 100%; }
    .pivot-scope-card > details > summary > i { margin-left: auto; }
}
@media (max-width: 560px) {
    #custom-reports-view .pivot-designer-workspace > .report-builder-card { padding: 12px; }
    .pivot-wells { gap: 7px; }
    .pivot-well { padding: 8px; min-height: 130px; }
    .pivot-chip { padding: 0 4px; gap: 4px; }
    .pivot-chip-options { font-size: 11px; }
    .pivot-chip-options small { font-size: 9.5px; max-width: 110px; }
    .pivot-chip-remove { width: 20px; }
    .pivot-chip .pivot-drag-handle { display: none; }
    .pivot-designer-toolbar { flex-wrap: wrap; }
    .pivot-designer-toolbar > span { font-size: 12px; }
    .pivot-designer-toolbar .btn { padding: 6px 9px; }
    .pivot-field-placement > div { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .pivot-palette-field { font-size: 11.5px; gap: 6px; }
    .pivot-filter-settings .custom-report-filter-rule { grid-template-columns: minmax(0,1fr) 28px; }
    .pivot-filter-settings .custom-report-filter-control:nth-child(2), .pivot-filter-settings .custom-report-filter-control:nth-child(3) { grid-column: 1 / 3; }
    .pivot-filter-settings .custom-report-filter-remove { grid-column: 2; }
    .pivot-canvas .custom-report-actions .btn { flex: 1; }
    .pivot-canvas .custom-pivot-kpis { gap: 12px; flex-wrap: wrap; }
}
