/*
 * w2ui-pivot.css  v1.0.0
 * Styled to match w2ui design system
 */

/* =========================================================================
   CONTAINER
   ========================================================================= */

.w2ui-pivot {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    box-sizing: border-box;
    font-family: OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 12px;
    color: #444;
    background: #fcfcfc;
    border: 1px solid #e1e1e1;
    border-radius: 3px;
    overflow: hidden;
    min-height: 200px;
}

/* =========================================================================
   CONTROL PANEL (left sidebar)
   ========================================================================= */

.pvt-panel {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    width: 220px;
    min-width: 180px;
    background: #f5f5f5;
    border-right: 1px solid #e1e1e1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ── Toolbar row ─────────────────────────────────────────────────────────── */

.pvt-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    padding: 6px 8px;
    background: #fafafa;
    border-bottom: 1px solid #e7e7e7;
    user-select: none;
}

.pvt-sel-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.pvt-sel-label {
    font-size: 10px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-left: 2px;
}

.pvt-select {
    height: 26px;
    padding: 2px 22px 2px 6px;
    font-size: 12px;
    font-family: inherit;
    color: #444;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    border: 1px solid #e0e0e0;
    border-radius: 3px;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    outline: none;
    min-width: 100px;
    max-width: 195px;
}

.pvt-select:hover  { border-color: #b9b9b9; }
.pvt-select:focus  { border-color: #269DF0; box-shadow: 0 0 0 2px rgba(38,157,240,0.15); }

.pvt-val-sel { min-width: 120px; }

/* ── Drop zones ──────────────────────────────────────────────────────────── */

.pvt-zones {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    padding: 6px;
    gap: 6px;
    min-height: 0;
}

/* Unused fields zone grows to fill remaining space and scrolls */
.pvt-zone[data-zone="unused"] {
    flex: 1 1 0;
    min-height: 60px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pvt-zone[data-zone="unused"] .pvt-pills {
    flex: 1 1 0;
    overflow-y: auto;
    align-content: flex-start;
}

.pvt-zone {
    background: #fff;
    border: 1px solid #e1e1e1;
    border-radius: 3px;
    overflow: hidden;
}

.pvt-zone-hdr {
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: #f5f5f5;
    border-bottom: 1px solid #efefef;
    user-select: none;
}

.pvt-pills {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 4px;
    padding: 6px;
    min-height: 36px;
    transition: background 0.12s;
}

.pvt-pills.pvt-pills-over {
    background: #EFF6FF;
    border-color: #93C5FD;
}

/* ── Field pills ─────────────────────────────────────────────────────────── */

.pvt-pill {
    display: inline-flex;
    align-items: center;
    gap: 0;
    height: 22px;
    max-width: 100%;
    padding: 0 0 0 7px;
    background: #fff;
    border: 1px solid #d2d2d2;
    border-radius: 11px;
    cursor: grab;
    user-select: none;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: border-color 0.1s, box-shadow 0.1s;
    white-space: nowrap;
    overflow: hidden;
}

.pvt-pill:hover {
    border-color: #269DF0;
    box-shadow: 0 1px 4px rgba(38,157,240,0.2);
}

.pvt-pill.pvt-pill-dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.pvt-pill.pvt-pill-filtered {
    border-color: #FB8822;
    background: #FFF8F3;
}

.pvt-pill-name {
    font-size: 11px;
    color: #444;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.pvt-pill-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 20px;
    height: 22px;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-left: 1px solid transparent;
    cursor: pointer;
    color: #aaa;
    font-size: 11px;
    line-height: 1;
    transition: color 0.1s, background 0.1s;
    border-radius: 0 11px 11px 0;
}

.pvt-pill-btn:hover {
    color: #444;
    background: rgba(0,0,0,0.05);
}

.pvt-pill-filter-btn {
    font-size: 9px;
}

.pvt-pill-remove-btn {
    font-size: 14px;
    font-weight: 300;
    border-left-color: #efefef;
}

.pvt-pill-remove-btn:hover {
    color: #e53e3e;
    background: #fff5f5;
}

/* =========================================================================
   OUTPUT PANEL
   ========================================================================= */

.pvt-output {
    flex: 1 1 auto;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.pvt-output-scroll {
    flex: 1 1 auto;
    overflow: auto;
    padding: 0;
}

/* =========================================================================
   PIVOT TABLE
   ========================================================================= */

.pvt-table {
    border-collapse: collapse;
    border-spacing: 0;
    font-size: 12px;
    color: #444;
    width: auto;
    min-width: 100%;
}

/* ── Header cells ─────────────────────────────────────────────────────────── */

.pvt-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 6px 12px;
    font-weight: 700;
    white-space: nowrap;
    background: linear-gradient(to bottom, #fafafa, #f2f2f2);
    border: 1px solid #e1e1e1;
    border-bottom-color: #d2d2d2;
    text-align: center;
}

.pvt-th-row-dim {
    text-align: left;
    background: linear-gradient(to bottom, #fafafa, #f2f2f2);
    color: #555;
    z-index: 3;
    left: 0;
}

.pvt-th-col {
    color: #444;
    min-width: 72px;
}

.pvt-th-col-group {
    color: #555;
    border-bottom-color: #e1e1e1;
    background: linear-gradient(to bottom, #f5f5f5, #efefef);
}

.pvt-th-total {
    color: #444;
    background: linear-gradient(to bottom, #f0f0f0, #e8e8e8);
    min-width: 72px;
}

/* ── Data cells ──────────────────────────────────────────────────────────── */

.pvt-table td {
    padding: 4px 10px;
    border: 1px solid #f0f0f0;
    white-space: nowrap;
}

.pvt-td-row-dim {
    font-weight: 600;
    color: #444;
    background: #fafafa;
    border-color: #ececec;
    text-align: left;
    position: sticky;
    left: 0;
    z-index: 1;
}

.pvt-td-val {
    text-align: right;
    color: #333;
}

.pvt-td-row-total {
    text-align: right;
    font-weight: 600;
    background: #f7f7f7;
    border-color: #e1e1e1;
    color: #333;
}

/* ── Totals row ───────────────────────────────────────────────────────────── */

.pvt-row-total td {
    font-weight: 700;
    background: #f2f2f2;
    border-color: #d2d2d2;
    border-top: 2px solid #d2d2d2;
}

.pvt-td-total-label {
    text-align: left !important;
    color: #555;
}

.pvt-td-col-total {
    text-align: right;
    color: #333;
}

.pvt-td-grand-total {
    text-align: right;
    color: #111;
    background: #eaeaea !important;
}

/* ── Zebra striping ───────────────────────────────────────────────────────── */

.pvt-row-odd  .pvt-td-val { background: #fff; }
.pvt-row-even .pvt-td-val { background: #fafcff; }

.pvt-table tbody tr:hover td {
    background: #EFF6FF !important;
}

.pvt-row-total:hover td {
    background: #e8e8e8 !important;
}

/* =========================================================================
   FILTER MENU (floating)
   ========================================================================= */

.pvt-filter-menu {
    position: absolute;
    z-index: 9999;
    width: 240px;
    background: #fff;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    font-size: 12px;
    color: #444;
    font-family: OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overflow: hidden;
}

.pvt-filter-menu-hdr {
    padding: 8px 12px;
    background: #f5f5f5;
    border-bottom: 1px solid #e7e7e7;
    font-weight: 600;
    color: #555;
}

.pvt-filter-menu-actions {
    display: flex;
    gap: 6px;
    padding: 6px 10px;
    border-bottom: 1px solid #f0f0f0;
}

.pvt-filter-menu-list {
    max-height: 220px;
    overflow-y: auto;
    padding: 4px 0;
}

.pvt-filter-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 12px;
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.08s;
}

.pvt-filter-item:hover {
    background: #f5f9ff;
}

.pvt-filter-item input[type="checkbox"] {
    accent-color: #269DF0;
    flex: 0 0 auto;
    cursor: pointer;
}

.pvt-filter-menu-footer {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid #efefef;
    background: #fafafa;
}

/* =========================================================================
   w2ui BUTTON OVERRIDES / FALLBACK
   (only applied when .w2ui-btn isn't already defined by w2ui.css)
   ========================================================================= */

.pvt-filter-menu .w2ui-btn,
.pvt-filter-menu-actions .w2ui-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 26px;
    padding: 0 10px;
    font-size: 11px;
    font-family: inherit;
    color: #555;
    background: linear-gradient(to bottom, #f0f0f0, #e4e4e4);
    border: 1px solid #ccc;
    border-radius: 13px;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: background 0.1s;
}

.pvt-filter-menu .w2ui-btn:hover {
    background: linear-gradient(to bottom, #e8e8e8, #d8d8d8);
    border-color: #bbb;
    color: #333;
}

.pvt-filter-menu .w2ui-btn-blue {
    color: #fff;
    background: linear-gradient(to bottom, #3baef5, #269DF0);
    border-color: #1e88d9;
    text-shadow: 0 1px 1px rgba(0,0,0,0.15);
}

.pvt-filter-menu .w2ui-btn-blue:hover {
    background: linear-gradient(to bottom, #2ea3ed, #1e8ee0);
}

/* =========================================================================
   EMPTY / ERROR STATES
   ========================================================================= */

.pvt-error {
    padding: 20px 24px;
    color: #c0392b;
    background: #fff5f5;
    border: 1px solid #fca5a5;
    border-radius: 3px;
    margin: 12px;
    font-size: 12px;
}

/* =========================================================================
   TOAST NOTIFICATION
   ========================================================================= */

.pvt-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    padding: 8px 18px;
    background: rgba(50,50,60,0.9);
    color: #fff;
    border-radius: 14px;
    font-size: 12px;
    font-family: OpenSans, sans-serif;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    pointer-events: none;
    transition: opacity 0.4s;
    opacity: 1;
    max-width: 480px;
    text-align: center;
}

/* =========================================================================
   RESPONSIVE / COMPACT
   ========================================================================= */

@media (max-width: 600px) {
    .w2ui-pivot {
        flex-direction: column;
    }
    .pvt-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e1e1e1;
    }
}
