/* ============================================================
   TABELA DINÂMICA — Estilos escopados
============================================================ */

.pe-pivot-badge {
  display: inline-block; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 2px 10px; border-radius: 20px;
  background: rgba(19,81,180,0.1); color: var(--interactive, #1351b4);
  margin-bottom: 0.5rem;
}

.pe-pivot-header { margin-bottom: 1rem; }
.pe-pivot-header h1 {
  font-size: 1.4rem; font-weight: 700; color: var(--color-primary-default, #1351b4);
  margin: 0 0 0.35rem; display: flex; align-items: center; gap: 0.5rem;
}
.pe-pivot-header p {
  font-size: 0.875rem; color: var(--color-secondary-07, #555);
  line-height: 1.6; margin: 0;
}

/* --- Info bar --- */
.pe-info-bar {
  background: var(--gray-2, #f8f9fa); border: 1px solid var(--border-color, #dee2e6);
  border-radius: 6px; padding: 0.625rem 1rem; margin-bottom: 1rem;
  font-size: 0.8rem; color: #555; line-height: 1.5;
}
.pe-info-bar strong { color: var(--interactive, #1351b4); }

/* --- Layout grid --- */
.pe-pivot-layout {
  display: grid; grid-template-columns: 320px 1fr;
  gap: 1rem; align-items: start;
}

.pe-main-area {
  min-width: 0; /* Permite que o container comprima e ative o scroll do filho (table-wrap) no CSS Grid */
}

@media (max-width: 1100px) {
  .pe-pivot-layout { grid-template-columns: 1fr; }
  .pe-sidebar { order: 2; }
  .pe-main-area { order: 1; }
}

/* --- Sidebar --- */
.pe-sidebar {
  background: #fff; border: 1px solid var(--border-color, #dee2e6);
  border-radius: 6px; overflow: hidden;
}

.pe-sidebar-title {
  background: var(--gray-2, #f8f9fa); border-bottom: 1px solid var(--border-color, #dee2e6);
  padding: 0.75rem 1rem; font-weight: 700; font-size: 0.85rem;
  color: var(--color-primary-pastel-01, #071d41);
  display: flex; align-items: center; gap: 0.5rem;
}

.pe-sidebar-search {
  padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--border-color, #dee2e6);
}
.pe-sidebar-search input {
  width: 100%; height: 34px; border: 1px solid #ccc; border-radius: 4px;
  padding: 0 0.625rem; font-size: 0.8rem;
  font-family: 'Rawline', 'Raleway', sans-serif;
}
.pe-sidebar-search input:focus {
  outline: 2px solid var(--interactive, #1351b4); border-color: var(--interactive, #1351b4);
}

.pe-fields-list {
  padding: 0.5rem 0.75rem; display: flex; flex-direction: column; gap: 5px;
  max-height: 220px; overflow-y: auto;
}

.pe-field-item {
  border: 1px solid #ddd; background: #fff; border-radius: 4px;
  padding: 6px 8px; cursor: grab; display: flex; justify-content: space-between;
  align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600;
  color: var(--color-primary-pastel-01, #071d41);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.pe-field-item:hover {
  border-color: var(--interactive, #1351b4);
  box-shadow: 0 1px 4px rgba(19,81,180,0.12);
}
.pe-field-item:active { cursor: grabbing; }
.pe-field-item .pe-field-type {
  font-weight: 400; font-size: 0.68rem; padding: 1px 6px;
  border-radius: 10px; white-space: nowrap;
}
.pe-field-type--dim { background: #dbe8fb; color: #1351b4; }
.pe-field-type--measure { background: #d4edda; color: #0a7b5a; }

/* --- Drop zones --- */
.pe-zones {
  border-top: 1px solid var(--border-color, #dee2e6);
  background: var(--gray-2, #fafafa); padding: 0.75rem;
}
.pe-zones h3 {
  margin: 0 0 0.5rem; font-size: 0.82rem; font-weight: 700;
  color: var(--color-primary-pastel-01, #071d41);
}

.pe-drop-zone {
  border: 1px dashed #bbb; background: #fff; min-height: 42px;
  margin-bottom: 0.5rem; padding: 6px; border-radius: 4px;
  transition: background 0.15s, border-color 0.15s;
}
.pe-drop-zone.over {
  background: #dbe8fb; border-color: var(--interactive, #1351b4);
}

.pe-zone-label {
  font-weight: 700; font-size: 0.72rem; margin-bottom: 4px;
  display: flex; justify-content: space-between; align-items: center;
  color: #444; text-transform: uppercase; letter-spacing: 0.03em;
}
.pe-zone-label small {
  font-weight: 400; text-transform: none; color: #888; letter-spacing: 0;
}

.pe-zone-items { display: flex; flex-wrap: wrap; gap: 4px; }

.pe-zone-chip {
  background: #dbe8fb; color: #1351b4; border: 1px solid #b9d3ff;
  border-radius: 4px; padding: 3px 6px; font-weight: 600; font-size: 0.72rem;
  display: inline-flex; align-items: center; gap: 4px; cursor: grab;
}
.pe-zone-chip button {
  border: 0; background: transparent; cursor: pointer; font-weight: 700;
  padding: 0 2px; line-height: 1; font-size: 0.75rem;
}
.pe-chip-remove { color: #c0392b; }
.pe-chip-move {
  color: #1351b4; border: 1px solid #b9d3ff; background: #fff;
  border-radius: 2px; padding: 0 3px; font-size: 0.65rem;
}

/* --- Config bar --- */
.pe-config-bar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 0.75rem; font-size: 0.8rem;
}
.pe-config-bar label {
  display: inline-flex; align-items: center; gap: 0.25rem;
  cursor: pointer; color: #333;
}
.pe-config-bar select {
  height: 30px; border: 1px solid #ccc; border-radius: 4px;
  background: #fff; font-size: 0.8rem; padding: 0 0.5rem;
  font-family: 'Rawline', 'Raleway', sans-serif;
}

.pe-btn {
  border: 1px solid var(--interactive, #1351b4); background: #fff;
  color: var(--interactive, #1351b4); border-radius: 4px;
  padding: 5px 10px; cursor: pointer; font-weight: 600; font-size: 0.75rem;
  font-family: 'Rawline', 'Raleway', sans-serif;
  transition: background 0.15s, color 0.15s;
  display: inline-flex; align-items: center; gap: 4px;
}
.pe-btn:hover { background: var(--interactive, #1351b4); color: #fff; }
.pe-btn:focus-visible {
  outline: 3px solid var(--focus-color, #c49c00); outline-offset: 2px;
}
.pe-btn--primary {
  background: var(--interactive, #1351b4); color: #fff;
}
.pe-btn--primary:hover { background: #0c44ac; }

/* --- Period filter --- */
.pe-period-panel {
  background: #fff; border: 1px solid var(--border-color, #dee2e6);
  border-radius: 6px; padding: 0.75rem 1rem; margin-bottom: 0.75rem;
}
.pe-period-panel h3 {
  margin: 0 0 0.5rem; font-size: 0.82rem; font-weight: 700;
  color: var(--color-primary-pastel-01, #071d41);
  display: flex; align-items: center; gap: 0.375rem;
}
.pe-period-grid {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end;
}
.pe-period-group { display: flex; flex-direction: column; gap: 2px; }
.pe-period-group label {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: #555;
}
.pe-period-group select {
  height: 32px; border: 1px solid #ccc; border-radius: 4px;
  background: #fff; font-size: 0.8rem; padding: 0 0.5rem;
  font-family: 'Rawline', 'Raleway', sans-serif;
  min-width: 100px;
}

/* --- Filters & Slicers panels --- */
.pe-filters-panel, .pe-slicers-panel {
  background: #fff; border: 1px solid var(--border-color, #dee2e6);
  border-radius: 6px; padding: 0.75rem 1rem; margin-bottom: 0.75rem;
  display: none;
}
.pe-filters-panel h3, .pe-slicers-panel h3 {
  margin: 0 0 0.5rem; font-size: 0.82rem; font-weight: 700;
  color: var(--color-primary-pastel-01, #071d41);
}
.pe-filter-grid { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.pe-filter-box { min-width: 160px; }
.pe-filter-box label {
  display: block; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; color: #555;
  margin-bottom: 2px;
}
.pe-filter-box select {
  width: 100%; height: 32px; border: 1px solid #ccc; border-radius: 4px;
  background: #fff; font-size: 0.8rem; padding: 0 0.5rem;
  font-family: 'Rawline', 'Raleway', sans-serif;
}

.pe-slicer-options {
  display: flex; flex-wrap: wrap; gap: 5px; max-height: 120px;
  overflow-y: auto; padding: 2px 0;
}
.pe-slicer-chip {
  border: 1px solid #ccc; background: #fff; color: #333;
  border-radius: 999px; padding: 4px 10px; cursor: pointer;
  font-size: 0.72rem; font-weight: 600;
  font-family: 'Rawline', 'Raleway', sans-serif;
  transition: all 0.15s;
}
.pe-slicer-chip:hover { border-color: var(--interactive, #1351b4); }
.pe-slicer-chip.active {
  background: var(--interactive, #1351b4); border-color: var(--interactive, #1351b4);
  color: #fff;
}
.pe-slicer-chip:focus-visible {
  outline: 3px solid var(--focus-color, #c49c00); outline-offset: 1px;
}

/* --- Table --- */
.pe-table-toolbar {
  display: flex; align-items: center; gap: 0.75rem; color: #666;
  margin-bottom: 0.5rem; font-size: 0.78rem; flex-wrap: wrap;
}

.pe-table-wrap {
  border: 1px solid var(--border-color, #dee2e6); border-radius: 6px;
  background: #fff; overflow: auto; max-height: 600px;
}
.pe-table-wrap table {
  border-collapse: collapse; width: max-content; min-width: 100%; font-size: 0.8rem;
  font-family: 'Rawline', 'Raleway', sans-serif;
}
.pe-table-wrap th, .pe-table-wrap td {
  border-right: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8;
  padding: 7px 10px; white-space: nowrap; background: #fff;
}
.pe-table-wrap th {
  background: var(--gray-2, #f8f9fa); text-align: left;
  position: sticky; top: 0; z-index: 2; font-weight: 700;
  color: var(--color-primary-pastel-01, #071d41); font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.02em;
}
.pe-table-wrap td.num, .pe-table-wrap th.num { text-align: right; }
.pe-table-wrap tbody tr:nth-child(even) td { background: #fcfcfc; }
.pe-table-wrap .rowno {
  width: 36px; text-align: center; color: #999; font-size: 0.72rem;
}

.pe-level-1 { font-weight: 700; color: #0c44ac; }
.pe-level-2 { font-weight: 600; color: #333; }
.pe-level-3 { color: #444; }
.pe-level-4 { color: #555; }
.pe-level-5 { color: #666; }

.pe-indent-1 { padding-left: 24px !important; }
.pe-indent-2 { padding-left: 44px !important; }
.pe-indent-3 { padding-left: 64px !important; }
.pe-indent-4 { padding-left: 84px !important; }

.pe-subtotal td { background: #f0f4ff !important; font-weight: 700; }
.pe-grand-total td {
  background: #dbeafe !important; font-weight: 800;
  color: var(--color-primary-pastel-01, #071d41);
}

.pe-toggle {
  border: 1px solid #bbb; background: #fff; width: 18px; height: 18px;
  padding: 0; margin-right: 5px; cursor: pointer; font-weight: 700;
  line-height: 16px; border-radius: 2px; font-size: 0.75rem;
  color: var(--interactive, #1351b4);
  transition: background 0.15s;
}
.pe-toggle:hover { background: #dbe8fb; }
.pe-toggle:focus-visible {
  outline: 3px solid var(--focus-color, #c49c00); outline-offset: 1px;
}

.pe-placeholder-toggle { display: inline-block; width: 23px; }

.pe-empty-state {
  text-align: center; padding: 3rem 1rem; color: #888;
  font-size: 0.9rem;
}
.pe-empty-state i { font-size: 2rem; margin-bottom: 0.5rem; display: block; color: #ccc; }

.pe-note {
  color: #888; margin-top: 0.75rem; font-size: 0.72rem;
  display: flex; align-items: center; gap: 0.25rem;
}

/* --- Sort indicator --- */
.pe-sort { color: #bbb; font-size: 0.6rem; margin-left: 3px; }

/* --- Scroll hint for mobile --- */
.pe-scroll-hint {
  display: none; font-size: 0.72rem; color: #888;
  margin-bottom: 0.25rem;
}
@media (max-width: 768px) {
  .pe-scroll-hint { display: block; }
  .pe-table-wrap { max-height: 450px; }
}
