/* Pivot Table OLAP Styles */

/* Контейнер зон перетягування */
.pivot-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* Зони для drag-and-drop полів */
.pivot-zones {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 1rem;
    min-height: 100px;
}

.pivot-zone {
    border: 2px dashed var(--gray-border, #e5e7eb);
    border-radius: 0.5rem;
    padding: 0.75rem;
    min-height: 60px;
    background: var(--gray-bg, #f8fafc);
    transition: all 0.2s;
}

.pivot-zone.drag-over {
    border-color: var(--blue-primary, #2563eb);
    background: rgba(37, 99, 235, 0.05);
}

.pivot-zone-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Доступні поля */
.pivot-fields-container {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.pivot-fields-section {
    flex: 1;
    min-width: 200px;
}

.pivot-fields-section h4 {
    font-size: 0.8rem;
    color: var(--text-secondary, #6b7280);
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--gray-border, #e5e7eb);
}

/* Поле (chip) */
.pivot-field {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--card-bg, #fff);
    border: 1px solid var(--gray-border, #e5e7eb);
    border-radius: 0.375rem;
    font-size: 0.75rem;
    cursor: grab;
    user-select: none;
    transition: all 0.15s;
    margin: 0.125rem;
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pivot-field:hover {
    border-color: var(--blue-primary, #2563eb);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    max-width: none;
}

.pivot-field.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.pivot-field.in-use {
    background: var(--blue-primary, #2563eb);
    color: white;
    border-color: var(--blue-dark, #1e40af);
}

.pivot-field-icon {
    font-size: 0.75rem;
    flex-shrink: 0;
}

.pivot-field-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pivot-field-remove {
    margin-left: 0.125rem;
    cursor: pointer;
    opacity: 0.7;
    font-size: 0.65rem;
    flex-shrink: 0;
}

.pivot-field-remove:hover {
    opacity: 1;
}

/* Рядки та колонки */
.pivot-rows-zone,
.pivot-cols-zone {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: flex-start;
    align-content: flex-start;
}

.pivot-values-zone {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Filters zone */
.pivot-filters-zone {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

/* Value field with aggregation */
.pivot-value-field {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.pivot-value-field select {
    font-size: 0.7rem;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    border: 1px solid var(--gray-border);
    background: var(--input-bg, #fff);
    color: var(--gray-text);
}

/* Pivot Table Result */
.pivot-table-wrapper {
    overflow: auto;
    max-height: 70vh;
    border: 1px solid var(--gray-border, #e5e7eb);
    border-radius: 0.5rem;
}

.pivot-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.pivot-table th,
.pivot-table td {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-border, #e5e7eb);
    text-align: left;
}

.pivot-table th {
    background: var(--gray-bg, #f3f4f6);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
    white-space: nowrap;
}

.pivot-table td {
    background: var(--card-bg, #fff);
}

.pivot-table td.numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.pivot-table tr:hover td {
    background: rgba(59, 130, 246, 0.05);
}

/* Row headers */
.pivot-table .row-header {
    background: var(--gray-bg, #f8fafc);
    font-weight: 500;
    position: sticky;
    left: 0;
    z-index: 5;
}

/* Totals row */
.pivot-table .total-row td {
    background: #FEF3C7;
    font-weight: 600;
}

.pivot-table .subtotal-row td {
    background: #F3F4F6;
    font-weight: 500;
}

/* Column header levels */
.pivot-table .col-header-level-0 {
    background: var(--blue-primary, #2563eb);
    color: white;
}

.pivot-table .col-header-level-1 {
    background: rgba(37, 99, 235, 0.1);
}

/* Expand/Collapse */
.pivot-expand-btn {
    cursor: pointer;
    margin-right: 0.25rem;
    font-size: 0.75rem;
    user-select: none;
}

/* Dark theme */
[data-theme="dark"] .pivot-zone {
    background: #1f2937;
    border-color: #374151;
}

[data-theme="dark"] .pivot-zone.drag-over {
    background: rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] .pivot-field {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

[data-theme="dark"] .pivot-field.in-use {
    background: #3b82f6;
    border-color: #2563eb;
}

[data-theme="dark"] .pivot-table th {
    background: #374151;
    color: #f9fafb;
}

[data-theme="dark"] .pivot-table td {
    background: #1f2937;
    color: #f9fafb;
}

[data-theme="dark"] .pivot-table .row-header {
    background: #111827;
}

[data-theme="dark"] .pivot-table .total-row td {
    background: #78350f;
}

[data-theme="dark"] .pivot-table .subtotal-row td {
    background: #374151;
}

/* Layout zones */
.pivot-layout {
    display: grid;
    grid-template-areas:
        "filters filters"
        "rows cols"
        "rows values";
    grid-template-columns: minmax(180px, 220px) 1fr;
    grid-template-rows: auto auto 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.pivot-filters-area {
    grid-area: filters;
}

.pivot-rows-area {
    grid-area: rows;
    max-width: 220px;
}

.pivot-cols-area {
    grid-area: cols;
}

.pivot-values-area {
    grid-area: values;
}

/* Responsive */
@media (max-width: 768px) {
    .pivot-layout {
        grid-template-areas:
            "filters"
            "rows"
            "cols"
            "values";
        grid-template-columns: 1fr;
    }
    
    .pivot-rows-area {
        max-width: 100%;
    }
    
    .pivot-zones {
        grid-template-columns: 1fr;
    }
    
    .pivot-field {
        font-size: 0.7rem;
        padding: 0.25rem 0.375rem;
    }
    
    .pivot-fields-container {
        flex-direction: column;
    }
    
    .pivot-fields-section {
        min-width: unset;
    }
}

/* Toolbar */
.pivot-toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.pivot-toolbar .btn-icon {
    padding: 0.5rem;
    min-width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty state */
.pivot-empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary, #6b7280);
}

.pivot-empty-state .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}
