/* ------------------------------------------------------------------------------------------------
   Pivot (data viewer) — `.pv-*`, used by Application.Client/Components/PivotView.razor.
   Built on the shadcn tokens in shadcn.css, so light and dark both come from the tokens. The grid
   itself reuses the data viewer's `.dvw-grid` AG Grid skin (ViewData.razor); only pivot-specific cells
   (row labels, totals, the grand-total row) are styled here.
   ------------------------------------------------------------------------------------------------ */

.pv { flex: 1 1 auto; min-height: 0; display: flex; gap: 14px; }
.pv-main { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* ---- top bar over the grid ---- */
.pv-bar {
    flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: 40px; padding: 5px 6px 5px 12px; border: 1px solid var(--border); border-bottom: 0;
    border-radius: 8px 8px 0 0; background: var(--surface-subtle); font-size: 12px; color: var(--text-muted);
}
.pv-bar-left { display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pv-bar-right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.pv-bar-strong { font-weight: 600; color: var(--text-secondary); }
.pv-bar-error { font-weight: 600; color: var(--danger); }
.pv-spin {
    width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--accent-border); border-top-color: var(--accent);
    animation: dvw-rotate .7s linear infinite;
}
.pv-check { display: inline-flex; align-items: center; gap: 6px; margin: 0 6px 0 0; font-size: 12.5px; color: var(--text-secondary); cursor: pointer; user-select: none; }
.pv-check input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); cursor: pointer; }

/* ---- grid stage ---- */
.pv-stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.pv-grid.dvw-grid { border-radius: 0 0 8px 8px; }
.pv-hidden { display: none !important; }
.pv-center {
    flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: 24px;
    border: 1px solid var(--border); border-radius: 0 0 8px 8px; background: var(--surface);
}
.pv-error-text { max-width: 520px; white-space: pre-wrap; word-break: break-word; }
.pv-empty-icon-error { color: var(--danger) !important; background: var(--danger-subtle) !important; border-color: var(--danger-border) !important; }
.pv-banner {
    position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 5;
    display: flex; align-items: flex-start; gap: 8px; padding: 8px 12px;
    border: 1px solid var(--danger-border); border-radius: 8px; background: var(--danger-subtle);
    color: var(--danger); font-size: 12.5px; box-shadow: var(--shadow-md);
}
.pv-banner svg { flex: 0 0 auto; margin-top: 2px; }

/* the empty-state illustration: a tiny schematic of where each area lands */
.pv-intro { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; max-width: 420px; }
.pv-intro .empty-text { line-height: 1.55; }
.pv-intro-art {
    display: grid; grid-template-columns: 64px 128px; grid-template-rows: 26px 56px; gap: 3px; margin-bottom: 10px;
    font-size: 10.5px; font-weight: 600; letter-spacing: .03em;
}
.pv-intro-cell { display: flex; align-items: center; justify-content: center; border-radius: 5px; border: 1px dashed var(--border-strong); color: var(--text-muted); }
.pv-intro-corner { border-style: solid; border-color: var(--border); background: var(--surface-subtle); }
.pv-intro-col { background: var(--info-subtle); border-color: var(--info-border); color: var(--info); }
.pv-intro-row { background: var(--success-subtle); border-color: var(--success-border); color: var(--success); }
.pv-intro-val { background: var(--accent-subtle); border-color: var(--accent-border); color: var(--text-primary); }

/* ---- pivot cells inside the shared .dvw-grid skin ---- */
.pv-grid .ag-header-group-cell { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.pv-grid .ag-header-group-text { font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--text-secondary); }
.pv-grid .pv-group-total .ag-header-group-text,
.pv-grid .pv-head-total .ag-header-cell-text { color: var(--text-primary); }
.pv-grid .pv-head-row .ag-header-cell-text { color: var(--text-secondary); }
.pv-grid .pv-rowhead { font-weight: 500; color: var(--text-primary); }
.pv-grid .pv-cell { font-variant-numeric: tabular-nums; }
.pv-grid .pv-cell-total { font-weight: 600; background: color-mix(in srgb, var(--surface-subtle) 60%, transparent); }
.pv-grid .pv-empty::before { content: "–"; color: var(--text-muted); opacity: .55; }
.pv-grid .ag-row-pinned.pv-grand .ag-cell { font-weight: 700; background: var(--surface-subtle); }
.pv-grid .ag-floating-bottom { border-top: 2px solid var(--border-strong); }

/* ---- field pane ---- */
.pv-pane {
    flex: 0 0 340px; min-height: 0; display: flex; flex-direction: column;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface); overflow: hidden;
}
.pv-pane-head { flex: 0 0 auto; padding: 11px 14px 8px; }
.pv-pane-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.pv-pane-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

.pv-search { position: relative; flex: 0 0 auto; padding: 0 12px 8px; }
.pv-search-icon { position: absolute; left: 22px; top: 10px; color: var(--text-muted); pointer-events: none; }
.sc .pv-search .input { height: 32px; padding-left: 30px; font-size: 12.5px; }

.pv-fields {
    flex: 1 1 140px; min-height: 96px; overflow-y: auto; padding: 2px 6px 8px;
    border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
    transition: background .12s ease;
}
.pv-fields.is-over { background: var(--danger-subtle); }
.pv-field {
    display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 4px 0 6px; border-radius: 6px;
    font-size: 12.5px; color: var(--text-primary); cursor: grab; user-select: none;
}
.pv-field:hover { background: var(--surface-subtle); }
.pv-field.is-dragging { opacity: .45; }
.pv-field.is-used .pv-field-name { font-weight: 600; }
.pv-field-special { margin-bottom: 2px; }
.pv-field-check { width: 14px; height: 14px; margin: 0; flex: 0 0 auto; accent-color: var(--accent); cursor: pointer; }
.pv-field-check-spacer { width: 14px; flex: 0 0 auto; }
.pv-field-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-field-add {
    appearance: none; flex: 0 0 auto; width: 22px; height: 22px; border-radius: 5px; border: 0; background: transparent;
    display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); cursor: pointer; opacity: 0;
    transition: opacity .1s ease, background .1s ease;
}
.pv-field:hover .pv-field-add, .pv-field-add:focus-visible, .pv-field-add.is-open { opacity: 1; }
.pv-field-add:hover, .pv-field-add.is-open { background: var(--surface); color: var(--text-primary); box-shadow: inset 0 0 0 1px var(--border); }
.pv-field-add:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (hover: none) { .pv-field-add { opacity: 1; } }
.pv-fields-empty { padding: 10px 8px; font-size: 12px; color: var(--text-muted); }

.pv-kind {
    flex: 0 0 auto; min-width: 30px; height: 18px; padding: 0 4px; border-radius: 4px;
    display: inline-flex; align-items: center; justify-content: center;
    font-family: var(--font-mono); font-size: 9.5px; font-weight: 500; letter-spacing: 0;
    background: var(--surface-subtle); border: 1px solid var(--border); color: var(--text-muted);
}
.pv-kind-int, .pv-kind-num { color: var(--info); background: var(--info-subtle); border-color: var(--info-border); }
.pv-kind-date, .pv-kind-time { color: var(--success); background: var(--success-subtle); border-color: var(--success-border); }
.pv-kind-count { color: var(--text-primary); background: var(--accent-subtle); border-color: var(--accent-border); font-size: 11px; }

.pv-menu {
    display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin: 2px 4px 6px 28px; padding: 4px;
    border: 1px solid var(--border); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow-sm);
}
.pv-menu-item {
    appearance: none; display: flex; align-items: center; gap: 6px; height: 26px; padding: 0 8px; border: 0; border-radius: 5px;
    background: transparent; font: inherit; font-size: 12px; color: var(--text-secondary); cursor: pointer; text-align: left;
}
.pv-menu-item:hover, .pv-menu-item:focus-visible { background: var(--surface-subtle); color: var(--text-primary); outline: none; }

/* ---- the four areas ---- */
.pv-zones {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 10px 12px 12px;
    display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(110px, auto); gap: 10px;
    background: var(--surface-muted);
}
.pv-zone { display: flex; flex-direction: column; min-width: 0; }
.pv-zone-head {
    display: flex; align-items: center; gap: 6px; padding: 0 2px 5px;
    font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted);
}
.pv-zone-icon { flex: 0 0 auto; }
.pv-zone-count {
    margin-left: auto; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--surface-subtle); border: 1px solid var(--border);
    font-size: 10px; letter-spacing: 0; color: var(--text-secondary);
}
.pv-zone-body {
    flex: 1 1 auto; min-height: 80px; display: flex; flex-direction: column; gap: 4px; padding: 5px;
    border: 1px dashed var(--border-strong); border-radius: 7px; background: var(--surface);
    transition: border-color .12s ease, background .12s ease;
}
.pv-zone-body.is-over { border-style: solid; border-color: var(--accent); background: var(--accent-subtle); }
.pv-zone-hint { margin: auto; padding: 4px; font-size: 11px; color: var(--text-muted); text-align: center; pointer-events: none; }

.pv-chip {
    position: relative; display: flex; flex-direction: column; gap: 4px; padding: 3px 3px 3px 2px;
    border: 1px solid var(--border); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow-xs);
}
.pv-zone-columns .pv-chip { border-left: 3px solid var(--info-border); }
.pv-zone-rows .pv-chip { border-left: 3px solid var(--success-border); }
.pv-zone-values .pv-chip { border-left: 3px solid var(--accent-border); }
.pv-zone-filters .pv-chip { border-left: 3px solid var(--warning-border); }
/* where a drop will land: a bar above the chip it would go in front of */
.pv-chip.is-before::before {
    content: ""; position: absolute; left: 4px; right: 4px; top: -4px; height: 2px; border-radius: 2px; background: var(--accent);
}
.pv-chip-head { display: flex; align-items: center; gap: 4px; min-width: 0; cursor: grab; }
.pv-chip-head.is-dragging { opacity: .45; }
.pv-grip { flex: 0 0 auto; display: inline-flex; color: var(--border-strong); padding: 0 1px; }
.pv-chip:hover .pv-grip { color: var(--text-muted); }
.pv-chip-name {
    flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 12px; font-weight: 500; color: var(--text-primary);
}
/* a chip's setting (aggregation, date grouping) shown as its label: reads as text, opens as a menu */
.pv-chip-select {
    appearance: none; -webkit-appearance: none; flex: 1 1 auto; min-width: 0; height: 22px;
    padding: 0 16px 0 3px; margin: 0; border: 0; border-radius: 4px; cursor: pointer;
    font: inherit; font-size: 12px; font-weight: 500; color: var(--text-primary);
    text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 3px center;
}
.pv-chip-select:hover { background-color: var(--surface-subtle); }
.pv-chip-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.pv-chip-select option { color: var(--text-primary); background: var(--surface); }

/* filter conditions stack, so the operator and the value each get the chip's full width */
.pv-chip-ctl { display: flex; flex-direction: column; gap: 3px; padding: 0 2px 1px 14px; }

.sc .pv-mini, .pv-mini {
    width: 100%; min-width: 0; height: 22px; padding: 0 4px;
    font: inherit; font-size: 11px; color: var(--text-secondary);
    border: 1px solid var(--border); border-radius: 4px; background: var(--surface-subtle); cursor: pointer;
}
.pv-mini:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--ring); }
.pv-mini-input { cursor: text; background: var(--surface); padding: 0 6px; color: var(--text-primary); }

.pv-x {
    appearance: none; flex: 0 0 auto; width: 20px; height: 20px; border: 0; border-radius: 4px; background: transparent;
    display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); cursor: pointer;
}
.pv-x:hover { background: var(--danger-subtle); color: var(--danger); }
.pv-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- narrow screens: the pane drops below the grid ---- */
@media (max-width: 960px) {
    .pv { flex-direction: column; }
    .pv-main { flex: 1 1 55%; }
    .pv-pane { flex: 0 0 auto; max-height: 48%; }
    .pv-fields { flex-basis: 110px; }
}

/* ---- saved pivot views (name chip, export menu, save dialog) ---- */
.pv-view {
    appearance: none; display: inline-flex; align-items: center; gap: 6px; max-width: 260px; height: 28px; padding: 0 10px;
    border: 1px solid var(--accent-border); border-radius: 999px; background: var(--accent-subtle);
    font: inherit; font-size: 12px; font-weight: 600; color: var(--text-primary); cursor: pointer;
}
.pv-view:hover { border-color: var(--accent); }
.pv-view svg { flex: 0 0 auto; color: var(--accent); }
.pv-view-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-view-edited {
    flex: 0 0 auto; padding: 1px 6px; border-radius: 999px; font-size: 10.5px; font-weight: 600;
    color: var(--warning); background: var(--warning-subtle); border: 1px solid var(--warning-border);
}
.pv-menu-backdrop { position: fixed; inset: 0; z-index: 39; }
.pv-dialog-note {
    margin: 0 0 12px; padding: 8px 10px; border-radius: 8px; font-size: 12.5px; line-height: 1.5;
    color: var(--text-secondary); background: var(--surface-subtle); border: 1px solid var(--border);
}
.pv-optional { font-weight: 400; color: var(--text-muted); }
.pv-dialog-check { margin: 0 0 4px; }
.pv-dialog-help { margin: 0 0 4px 20px; }
.pv-dialog-error { margin-top: 10px; }
.pv-foot-spacer { flex: 1 1 auto; }
.sc .btn.pv-danger { color: var(--danger) !important; }
