/* ── PivotGrid styles ─────────────────────────────────────────────────────── */

.pg-root {
  position: relative;
  overflow: hidden;
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
  user-select: none;
}

.pg-col-resize-handle:hover,
.pg-col-resize-handle:active {
  background: rgba(26, 115, 232, 0.25);
}

/* ── Scroll area ─────────────────────────────────────────────────────────── */

.pg-scroll {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: auto;
}

/* ── Column header ───────────────────────────────────────────────────────── */

.pg-col-header {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column; 
  align-items: flex-start;
  background: #fafafa;
  border-bottom: 1px solid #d0d0d0;
  z-index: 10;
}

.pg-col-header-cell {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 0 10px;
  box-sizing: border-box;
  font-size: 11px;
  font-weight: 500;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-right: 1px solid #e8e8e8;
  white-space: nowrap;
  overflow: hidden;
  background: #fafafa;
  padding-top: 6px
}

.pg-col-header-cell.row-label {
  justify-content: flex-start;
  color: #999;
  position: sticky;
  left: 0;
  background: #fafafa;
  z-index: 11;
  border-right: 1px solid #d0d0d0;
}

.pg-col-header-cell.total-col {
  color: #444;
  font-weight: 600;
}

/* ── Rows ────────────────────────────────────────────────────────────────── */

.pg-row {
  position: absolute;
  left: 0;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.08s;
}

.pg-row:hover {
  background: #f5f9ff !important;
}

.pg-row.grand-total {
  font-weight: 500;
  border-top: 1px solid #d0d0d0;
  background: #fafafa;
}

/* ── Row header cell (sticky left) ──────────────────────────────────────── */

.pg-cell-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  height: 100%;
  box-sizing: border-box;
  border-right: 1px solid #f0f0f0;
  overflow: hidden;
  white-space: nowrap;
  color: #1a1a1a;
  position: sticky;
  left: 0;
  background: inherit;
  z-index: 1;
}

.pg-cell-header .pg-label {
  margin-left: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pg-cell-header .pg-label.depth-0 {
  font-weight: 500;
  color: #1a1a1a;
  font-size: 13px;
}

.pg-cell-header .pg-label.depth-1 {
  font-weight: 400;
  color: #555;
  font-size: 12px;
}

.pg-cell-header .pg-label.depth-2 {
  font-weight: 400;
  color: #777;
  font-size: 12px;
}

/* ── Toggle button ───────────────────────────────────────────────────────── */

.pg-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
  color: #999;
  font-size: 10px;
  transition: transform 0.15s;
  border-radius: 3px;
}

.pg-toggle:hover {
  background: #e8e8e8;
  color: #333;
}

.pg-toggle.collapsed {
  transform: rotate(-90deg);
}

.pg-toggle-spacer {
  width: 16px;
  flex-shrink: 0;
  display: inline-block;
}

/* ── Value cells ─────────────────────────────────────────────────────────── */

.pg-cell {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  padding: 0 10px;
  box-sizing: border-box;
  border-right: 1px solid #f0f0f0;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  color: #2a2a2a;
  cursor: pointer;
  transition: background 0.08s, color 0.08s;
}

.pg-cell:hover {
  background: #e8f0fe;
  color: #1a73e8;
}

.pg-cell.total {
  background: #fafafa;
  color: #555;
  font-weight: 500;
}

.pg-cell.total:hover {
  background: #e8f0fe;
  color: #1a73e8;
}

.pg-cell.grand-total-val {
  font-weight: 600;
  color: #1a1a1a;
}

.pg-cell.empty {
  color: #ccc;
  cursor: default;
}

.pg-cell.empty:hover {
  background: transparent;
  color: #ccc;
}

.pg-col-header-group {
  border-bottom: 1px solid #d0d0d0;
  justify-content: flex-start;
  padding-left: 6px;
  font-weight: 600;
  color: #444;
}

.pg-cell.subtotal,
.pg-col-header-cell.subtotal-col {
  background: #f5f5f5;
  color: #555;
  border-left: 2px solid #d0d0d0;
}

.pg-row:hover .pg-cell.subtotal,
.pg-row--hover .pg-cell.subtotal {
  background: #f5f9ff !important;
}

.pg-row:hover .pg-cell:hover,
.pg-row--hover .pg-cell:hover {
  background: #e8f0fe !important;
  color: #1a73e8 !important;
}

.pg-row:hover .pg-cell.subtotal:hover,
.pg-row--hover .pg-cell.subtotal:hover {
  background: #e8f0fe !important;
  color: #1a73e8 !important;
}

.pg-cell--clicked {
  background: #c97b56 !important;
  color: #000 !important;
}

.pg-row:hover .pg-cell--clicked[data-pg-key],
.pg-row--hover .pg-cell--clicked[data-pg-key],
.pg-row:hover .pg-cell--clicked[data-pg-key]:hover,
.pg-row--hover .pg-cell--clicked[data-pg-key]:hover {
  background: #c97b56 !important;
  color: #000 !important;
}
    .fz-zone--filters { flex: 1.5; }

    [data-fz-zone="filters"] .fz-chip {
      background: #fff8f0;
      border-color: #f4c27a;
      color: #7a4200;
    }

    [data-fz-zone="filters"] .fz-chip:hover {
      border-color: #e67e22;
      color: #5d3100;
      box-shadow: 0 1px 4px rgba(230,126,34,0.2);
    }

    [data-fz-zone="filters"] .fz-chip.fz-chip--active {
      background: #fff0dc;
      border-color: #e67e22;
      font-weight: 500;
    }

    .fz-chip-label { cursor: pointer; }

 /* ── Field Zones ────────────────────────────────────────────────────── */
   
    .field-zones {
      display: flex;
      gap: 8px;
      padding: 8px 12px;
      background: #fff;
      border: 1px solid #e0e0e0;
      border-radius: 8px;
      min-height: 48px;
      align-items: stretch;
      margin-bottom: 8px;
      flex-shrink: 0;
    }

    .fz-zone {
      display: flex;
      flex-direction: column;
      gap: 4px;
      flex: 1;
      min-width: 0;
    }

    .fz-zone--rows    { flex: 2; }
    .fz-zone--columns { flex: 1.5; }
    .fz-zone--free    { flex: 1.5; }

    .fz-zone-label {
      font-size: 10px;
      font-weight: 600;
      color: #999;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      padding: 0 4px;
    }

    .fz-zone-body {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      min-height: 33px;
      max-height: 66px;
      overflow-y: auto;
      padding: 4px 6px;
      border: 1.5px dashed #d0d0d0;
      border-radius: 6px;
      background: #fff;
      transition: background 0.15s, border-color 0.15s;
    }

    .fz-zone-body.fz-zone--over {
      background: #e8f0fe;
      border-color: #1a73e8;
    }

    /* Chips */
    .fz-chip {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 3px 8px;
      background: #fff;
      border: 1px solid #d0d0d0;
      border-radius: 4px;
      font-size: 12px;
      color: #333;
      cursor: grab;
      user-select: none;
      white-space: nowrap;
      transition: box-shadow 0.1s, border-color 0.1s;
    }

    .fz-chip:hover {
      border-color: #1a73e8;
      color: #1a73e8;
      box-shadow: 0 1px 4px rgba(26,115,232,0.15);
    }

    /* Chips in rows/columns — slightly coloured */
    [data-fz-zone="rows"] .fz-chip {
      background: #f0f4ff;
      border-color: #c5d3f7;
      color: #2c4bad;
    }

    [data-fz-zone="columns"] .fz-chip {
      background: #f0fdf4;
      border-color: #a7d7b8;
      color: #1a6638;
    }

    .fz-chip--dragging {
      opacity: 0.35;
      cursor: grabbing;
    }

    .fz-chip--ghost {
      cursor: grabbing;
      box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }

    .fz-chip-remove {
      font-size: 13px;
      line-height: 1;
      color: #999;
      cursor: pointer;
      padding: 0 1px;
      border-radius: 2px;
    }

    .fz-chip-remove:hover {
      color: #e53935;
      background: #fde;
    }

    .fz-chip--filtered {
       border-color: #6172f3;
    }

    .fz-chip-hint {
      font-size: 10px;
      font-weight: 600;
      color: #6172f3;
      background: #eff4ff;
      border-radius: 4px;
      padding: 0 4px;
      margin-left: 2px;
      pointer-events: none;
    }

    .fz-tooltip {
      display: none;
      position: fixed;
      z-index: 10000;
      background: #fff;
      color: #344054;
      font-size: 12px;
      padding: 6px 10px;
      border: 1px solid #d0d5dd;
      border-radius: 6px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
      white-space: pre-wrap;
      max-width: 260px;
      pointer-events: none;
    }
/* ── Demo page styles ────────────────────────────────────────────────────── */

:where(.pg-widget, .pg-widget *, .pg-widget *::before, .pg-widget *::after) {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* body styling intentionally not provided here — see demo/*.html for the
   page-level shell styles used by the example pages. A component library
   should not impose font/background/padding on the host page's <body>. */

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

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 8px 12px;
}

.toolbar-label {
  font-size: 11px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.toolbar select {
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  outline: none;
  color: #333;
}

.toolbar select:focus {
  border-color: #1a73e8;
}

.toolbar-sep {
  width: 1px;
  height: 18px;
  background: #e0e0e0;
  flex-shrink: 0;
}

.toolbar-btn {
  padding: 4px 12px;
  font-size: 12px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  color: #333;
  transition: background 0.1s, border-color 0.1s;
  white-space: nowrap;
}

.toolbar-btn:hover:not(:disabled) {
  background: #f0f0f0;
  border-color: #bbb;
}

.toolbar-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.toolbar-stat {
  margin-left: auto;
  font-size: 11px;
  color: #aaa;
  white-space: nowrap;
}

/* ── Cache zone ──────────────────────────────────────────────────────────── */

.cache-zone {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.cache-zone-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.cache-zone-label {
  font-size: 11px;
  font-weight: 600;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Метр заполненности кэша */
.cache-meter-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.cache-meter-bar {
  flex: 1;
  height: 4px;
  background: #f0f0f0;
  border-radius: 2px;
  overflow: hidden;
  min-width: 60px;
}

.cache-meter-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.35s ease, background 0.35s;
}

.cache-meter-fill.ok     { background: #1a9e5c; }
.cache-meter-fill.warn   { background: #e67e22; }
.cache-meter-fill.danger { background: #e53935; }

.cache-meter-label {
  font-size: 11px;
  white-space: nowrap;
  color: #bbb;
  min-width: 120px;
}

.cache-meter-label.ok     { color: #1a9e5c; }
.cache-meter-label.warn   { color: #e67e22; }
.cache-meter-label.danger { color: #e53935; }

/* Статус кэша */
.cache-status {
  font-size: 11px;
  white-space: nowrap;
}

.cache-status.fresh { color: #1a9e5c; }
.cache-status.stale { color: #e67e22; font-weight: 500; }
.cache-status.empty { color: #ccc; }

/* Кнопка «Обновить кэш» — подсвечивается когда кэш stale */
.cache-refresh-btn--stale {
  border-color: #1a73e8 !important;
  color: #1a73e8 !important;
}

/* Fullscreen overlay при обновлении кэша */
#cache-fullscreen-loader {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: #999;
  z-index: 500;
}

/* Состояние загрузки кэша — блокируем все чипы */
.cache-zone--loading .cache-chip {
  pointer-events: none;
  opacity: 0.4;
}

.cache-zone--loading .cache-zone-label,
.cache-zone--loading .cache-meter-wrap,
.cache-zone--loading .cache-status {
  opacity: 0.4;
}

/* Кнопка в loading не меняет внешний вид при hover */
.cache-zone--loading #btn-refresh-cache {
  cursor: wait;
}

/* Чипы измерений */
.cache-zone-body {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 28px;
}

.cache-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  font-size: 12px;
  color: #666;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: border-color 0.1s, background 0.1s, color 0.1s;
}

.cache-chip:hover {
  border-color: #1a73e8;
  color: #1a73e8;
}

/* В кэше — синий (совпадает с зоной «Строки») */
.cache-chip.is-cached {
  background: #f0f4ff;
  border-color: #c5d3f7;
  color: #2c4bad;
}

.cache-chip.is-cached:hover {
  border-color: #e53935;
  background: #fff5f5;
  color: #c62828;
}

/* Идёт COUNT-запрос */
.cache-chip.is-checking {
  background: #fff8e6;
  border-color: #f0a500;
  color: #7a4f00;
  cursor: wait;
  animation: cache-pulse 0.9s ease-in-out infinite;
}

/* Отклонено — превышение лимита */
.cache-chip.is-rejected {
  background: #fff0f0;
  border-color: #e53935;
  color: #c62828;
  cursor: default;
  animation: cache-shake 0.3s ease-in-out;
}

@keyframes cache-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

@keyframes cache-shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-5px); }
  75%       { transform: translateX(5px); }
}

/* ── Toast ───────────────────────────────────────────────────────────────── */

.cache-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  font-size: 12px;
  padding: 8px 18px;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 300;
  white-space: nowrap;
  max-width: calc(100vw - 48px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.cache-toast.visible {
  opacity: 1;
}

/* ── Filter popup ────────────────────────────────────────────────────────── */

.fm-popup {
  position: fixed;
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  width: 280px;
  max-height: 420px;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  font-size: 13px;
}

.fm-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #efefef;
  font-weight: 500;
  font-size: 13px;
  flex-shrink: 0;
}

.fm-popup-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: #aaa;
  line-height: 1;
  padding: 0;
}

.fm-popup-close:hover { color: #333; }

.fm-search-section {
  padding: 8px 12px;
  border-bottom: 1px solid #efefef;
  flex-shrink: 0;
}

.fm-search-type {
  display: flex;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 12px;
  color: #555;
}

.fm-search-type label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.fm-search-input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  font-size: 12px;
  outline: none;
  box-sizing: border-box;
}

.fm-search-input:focus { border-color: #1a73e8; }

.fm-checkbox-list {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.fm-select-all-wrap {
  padding: 5px 12px !important;
  border-bottom: 1px solid #efefef;
  color: #888;
  font-style: italic;
}

.fm-checkbox-scroll {
  flex: 1;
  overflow-y: auto;
  max-height: 200px;
}

.fm-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 12px;
  color: #333;
}

.fm-checkbox:hover { background: #f5f9ff; }
.fm-checkbox input { cursor: pointer; }

.fm-no-checkboxes {
  padding: 12px;
  color: #aaa;
  font-size: 12px;
  font-style: italic;
}

.fm-popup-footer {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid #efefef;
  gap: 8px;
  flex-shrink: 0;
}

.fm-btn {
  padding: 5px 14px;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid #d0d0d0;
  background: #fff;
  color: #333;
}

.fm-btn:hover { background: #f0f0f0; }

.fm-btn-primary {
  background: #1a73e8;
  border-color: #1a73e8;
  color: #fff;
}

.fm-btn-primary:hover { background: #1558b0; }

/* Note: the grid container is #pivot-grid (see rule near the end of this
   file) — both the generated shell and the standalone demo use that id. */

/* ── Drillthrough panel ──────────────────────────────────────────────────── */

.dt-panel {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 300px;
  background: #fff;
  border-top: 1px solid #d0d0d0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  z-index: 100;
  flex-direction: column;
}

.dt-panel.visible {
  display: flex;
}

.dt-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #fafafa;
  border-bottom: 1px solid #e8e8e8;
  flex-shrink: 0;
}

.dt-header-label {
  font-size: 11px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dt-header-context {
  font-size: 13px;
  font-weight: 500;
  color: #1a1a1a;
}

.dt-header-value {
  font-size: 13px;
  color: #1a73e8;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.dt-header-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  color: #aaa;
  padding: 0 2px;
  transition: color 0.1s;
}

.dt-header-close:hover {
  color: #333;
}

.dt-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 16px;
  background: #fafafa;
  border-bottom: 1px solid #efefef;
  flex-shrink: 0;
}

.dt-filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  background: #e8f0fe;
  color: #1a73e8;
  font-size: 12px;
  border-radius: 10px;
}

.dt-filter-tag .tag-key {
  color: #5f8dd3;
}

.dt-body {
  flex: 1;
  overflow: auto;
}

.dt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.dt-table thead th {
  position: sticky;
  top: 0;
  background: #fafafa;
  padding: 6px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #e0e0e0;
  white-space: nowrap;
}

.dt-table thead th.num {
  text-align: right;
}

.dt-table tbody tr:nth-child(even) {
  background: #fafafa;
}

.dt-table tbody tr:hover {
  background: #f0f6ff;
}

.dt-table tbody td {
  padding: 5px 12px;
  color: #333;
  border-bottom: 1px solid #f4f4f4;
  white-space: nowrap;
}

.dt-table tbody td.num {
  text-align: right;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: #1a1a1a;
}

.dt-footer {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 6px 16px;
  background: #fafafa;
  border-top: 1px solid #efefef;
  font-size: 12px;
  color: #888;
  flex-shrink: 0;
}

.dt-footer strong {
  color: #1a1a1a;
  font-weight: 500;
}

.dt-footer .dt-warning {
  color: #e67e22;
}

.fz-chip-placeholder {
  display: inline-flex;
  width: 3px;
  height: 24px;
  background: #1a73e8;
  border-radius: 2px;
  margin: 0 2px;
  pointer-events: none;
}

.fz-chip[data-zone="rows"].fz-chip--last {
  background: #1a73e8 !important;
  border-color: #1a73e8 !important;
  color: #fff !important;
}

.fz-chip[data-zone="columns"].fz-chip--last {
  background: #1a6638 !important;
  border-color: #1a6638 !important;
  color: #fff !important;
}

.fz-chip[data-zone="free"].fz-chip--last {
  background: #666 !important;
  border-color: #666 !important;
  color: #fff !important;
}

.toolbar-btn--toggle.is-active {
  background: #e8f0fe;
  border-color: #1a73e8;
  color: #1a73e8;
}

.demo-toggles {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: #666;
  margin-bottom: 8px;
}

.demo-toggles label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

#pivot-grid {
  flex: 1;
  min-height: 200px;
  overflow: hidden;
}

.pg-listen-context {
  font-size: 12px;
  color: #555;
  background: #fff8e6;
  border: 1px solid #f0d98c;
  border-radius: 6px;
  padding: 6px 12px;
  margin-bottom: 8px;
}