/* =========================================
   1. VARIÁVEIS E TEMAS
   ========================================= */
:root {
  --app-ui-zoom: 0.67;
  --bg-app: #f3f6fb;
  --bg-panel: #ffffff;
  --bg-panel-2: #f8fafc;
  --border: #dbe3f0;
  --text-main: #0f172a;
  --text-soft: #64748b;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --primary: #3b82f6;
  --primary-2: #2563eb;
  --danger: #ef4444;
  --shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.05), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
}

body.theme-dark {
  --bg-app: #0f172a;
  --bg-panel: #1e293b;
  --bg-panel-2: #334155;
  --border: #334155;
  --text-main: #f8fafc;
  --text-soft: #94a3b8;
  --input-bg: #0f172a;
  --input-border: #334155;
  --primary: #4f8cff;
  --primary-2: #6aa0ff;
  --danger: #ef4444;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
}

/* =========================================
   2. BASE E TIPOGRAFIA
   ========================================= */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  zoom: var(--app-ui-zoom);
}

.hidden { display: none !important; }

/* =========================================
   3. LAYOUT PRINCIPAL (SHELL)
   ========================================= */
.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  padding: 24px 16px;
  border-right: 1px solid var(--border);
}

.content { padding: 24px; }

/* Painéis (Cards principais) */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel h2, .panel h3, .panel h4 { margin: 0 0 12px; }

/* Limpeza visual dos painéis dentro da sidebar */
.sidebar .panel {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0 0 24px 0;
  margin-bottom: 0;
  border-radius: 0;
}
.sidebar .panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-soft);
  margin-bottom: 12px;
}

/* =========================================
   4. TOPBAR E CABEÇALHOS
   ========================================= */
.topbar-panel {
  position: sticky;
  top: 0;
  z-index: 180;
  padding: 20px 24px;
  backdrop-filter: blur(10px);
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Inputs de Título do Dashboard inline */
.dashboard-title-box { min-width: 0; flex: 1; }
.dashboard-title-editable { cursor: text; display: inline-block; max-width: 100%; word-break: break-word; }
.dashboard-title-input {
  display: block; width: min(720px, 100%);
  font-size: 28px; font-weight: 700; line-height: 1.2;
  border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text-main);
  border-radius: 8px; padding: 8px 12px;
}
.dashboard-title-row, .dashboard-description-row { display: flex; align-items: flex-start; gap: 10px; }
.dashboard-description-editable {
  margin-top: 8px; min-height: 24px; max-width: min(820px, 100%);
  color: var(--text-soft); font-size: 14px; line-height: 1.6; cursor: text; word-break: break-word;
}
.dashboard-description-editable.is-empty { opacity: 0.8; }
.dashboard-description-input {
  display: block; width: min(820px, 100%); min-height: 80px; resize: vertical; margin-top: 8px;
  border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text-main);
  border-radius: 8px; padding: 10px 14px; font-size: 14px; line-height: 1.6;
}

.dashboard-tabs-panel { padding: 12px 16px; }
.dashboard-tabs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.dashboard-tabs-list {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}
.dashboard-tab-btn {
  height: 38px;
  max-width: 220px;
  padding: 0 12px;
  border-color: var(--border);
  background: var(--bg-panel-2);
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dashboard-tab-btn.is-active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}
.dashboard-tab-settings {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  color: var(--text-soft);
  font-size: 13px;
}
.dashboard-tab-settings .checkbox-inline { margin-right: 4px; }
.dashboard-tab-name-input {
  width: min(260px, 100%);
  min-height: 36px;
  height: 36px;
  padding: 6px 10px;
}
.dashboard-tab-action {
  height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

/* =========================================
   5. FORMULÁRIOS E INPUTS
   ========================================= */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-soft);
}
.field-span-2 { grid-column: span 2; }

input, select, textarea, button { font: inherit; }

input[type="file"], input[type="date"], input[type="number"],
input[type="text"], input[type="color"], select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-main);
  border-radius: 8px;
  padding: 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="color"] { padding: 4px; }

/* Foco nos campos */
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
body.theme-dark input:focus,
body.theme-dark select:focus,
body.theme-dark textarea:focus {
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.25);
}

/* =========================================
   6. BOTÕES (DESIGN SYSTEM)
   ========================================= */
/* Padrão Base */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--primary);
  color: #ffffff;
}

button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Secundários */
button.secondary {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #e2e8f0;
}
button.secondary:hover:not(:disabled) { background: #e2e8f0; }

body.theme-dark button.secondary {
  background: transparent;
  color: var(--text-soft);
  border-color: var(--border);
}
body.theme-dark button.secondary:hover:not(:disabled) {
  background: var(--bg-panel-2);
  color: var(--text-main);
}

/* Danger */
button.danger {
  background: var(--danger);
  color: #ffffff;
}
button.danger:hover:not(:disabled) { background: #dc2626; }

/* Botões de Ícone */
.icon-btn {
  width: 44px;
  padding: 0;
  font-size: 20px;
}

/* --- Ghost Buttons (Ações invisíveis até o hover) --- */
.card-actions button,
.inline-edit-btn {
  background: transparent;
  border-color: transparent;
  color: var(--text-soft);
  box-shadow: none;
}
.card-actions button.secondary:hover,
.inline-edit-btn:hover {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-main);
}
.card-actions button.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

/* Quick Add (+) - Fundo invisível, mas com borda */
.quick-add-toggle {
  width: 44px;
  padding: 0;
  font-size: 20px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
}
.quick-add-toggle:hover {
  background: var(--bg-panel-2);
}

/* Agrupamento de botões (Padrão) */
.button-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

/* Agrupamento de botões na Sidebar (Empilhados) */
.sidebar .button-row {
  flex-direction: column;
  width: 100%;
}
.sidebar .button-row button {
  width: 100%;
}

/* =========================================
   7. MENUS DROPDOWN E FEEDBACKS
   ========================================= */
.quick-add-menu { position: relative; }
.quick-add-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 170px; padding: 8px; background: var(--bg-panel-2);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  z-index: 100; display: flex; flex-direction: column; gap: 8px;
}
.quick-add-option { width: 100%; justify-content: flex-start; background: transparent; color: var(--text-main); }
.quick-add-option:hover { background: var(--bg-panel); color: var(--primary); }

#loadingInfo, #fileInfo, #summaryInfo { font-size: 13px; color: var(--text-soft); }
.data-refresh-btn {
  width: 100%;
  min-height: 36px;
  height: 36px;
  margin: -4px 0 10px;
  padding: 0 12px;
  font-size: 13px;
}
#appError {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px;
  background: #3b1111; color: #fee2e2; border: 1px solid #fca5a5;
}

/* =========================================
   8. GRIDS DE DADOS, KPIs E GRÁFICOS
   ========================================= */
#kpisContainer, #analysisContainer {
  display: grid;
  gap: 16px;
}
#kpisContainer { grid-template-columns: repeat(24, minmax(0, 1fr)); }
#analysisContainer { grid-template-columns: repeat(12, minmax(0, 1fr)); }
#kpisContainer > .empty-state, #analysisContainer > .empty-state {
  grid-column: 1 / -1;
  min-height: 88px;
}

.kpi-card, .analysis-card, .table-card, .empty-state {
  border: 1px solid var(--border);
  background: var(--bg-panel);
  border-radius: 12px;
}
.kpi-card, .analysis-card, .table-card { padding: 20px; }
.empty-state { padding: 20px; color: var(--text-soft); }

.span-micro { grid-column: span 3; }
.span-small { grid-column: span 4; }
.span-medium { grid-column: span 6; }
.span-large { grid-column: span 8; }
.span-full { grid-column: 1 / -1; }

#kpisContainer .span-nano { grid-column: span 3; }
#kpisContainer .span-micro { grid-column: span 6; }
#kpisContainer .span-small { grid-column: span 8; }
#kpisContainer .span-medium { grid-column: span 12; }
#kpisContainer .span-large { grid-column: span 16; }

.card-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px;
}
.card-title-wrap { min-width: 0; }
.card-title { margin: 0; font-size: 16px; font-weight: 700; }
.card-subtitle { margin-top: 4px; font-size: 12px; color: var(--text-soft); }
.card-actions { display: flex; gap: 8px; }
.card-actions button { width: 36px; height: 36px; padding: 0; font-size: 16px; }
.card-actions .card-move-btn {
  width: auto;
  min-width: 64px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
}
.card-drag-handle {
  cursor: grab;
  letter-spacing: -0.08em;
  color: var(--text-soft);
}
.card-drag-handle:active { cursor: grabbing; }
.kpi-card.is-dragging,
.analysis-card.is-dragging,
.table-card.is-dragging {
  opacity: 0.55;
  outline: 2px dashed var(--primary);
  outline-offset: 3px;
}
.card-download-wrap { position: relative; }
.card-move-wrap { position: relative; }
.card-download-btn {
  font-size: 11px !important;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.card-download-menu,
.card-move-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: none;
  min-width: 112px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  z-index: 30;
}
.card-move-menu { min-width: 170px; }
.card-download-menu.show,
.card-move-menu.show { display: grid; gap: 4px; }
.card-download-menu button,
.card-move-menu button {
  width: 100%;
  height: auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel-2);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  box-shadow: none;
}
.card-download-menu button:hover,
.card-move-menu button:hover {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.35);
}

.kpi-title { font-size: 16px; font-weight: 700; color: var(--text-soft); }
.kpi-value { margin-top: 10px; font-size: 36px; font-weight: 800; line-height: 1.1; }
.kpi-meta { margin-top: 8px; font-size: 13px; opacity: 0.85; word-break: break-word; }
.chart-host { min-height: 380px; }

.chart-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-panel-2);
  border-radius: 0 0 12px 12px;
}

.chart-pager .pager-actions button {
  height: 36px;
  padding: 0.35rem 0.95rem;
}

.chart-pager .pager-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chart-pager div:first-child {
  font-size: 0.85rem;
  color: var(--text-soft);
}

.kpi-value.kpi-error {
  color: var(--danger);
}

.kpi-warning-icon {
  margin-left: 0.35rem;
  font-size: 0.95em;
  vertical-align: middle;
  cursor: help;
}

.locale-warning-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 12px 16px;
  border-radius: 12px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  margin: 16px;
  box-shadow: var(--shadow);
  font-size: 0.95rem;
}

.locale-warning-banner .warning-icon {
  font-size: 1.2rem;
}

.locale-warning-banner .warning-text {
  line-height: 1.4;
}

.locale-warning-banner .locale-warning-dismiss {
  margin-left: 12px;
  background: transparent;
  border: none;
  color: #92400e;
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  padding: 0;
}

/* Tabelas */
.table-wrap { overflow: auto; border-radius: 8px; border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th, .data-table td { border-bottom: 1px solid var(--border); padding: 10px 14px; font-size: 13px; text-align: left; vertical-align: middle; }
.data-table th { background: var(--bg-panel-2); font-weight: 600; color: var(--text-soft); border-top: none; border-left: none; border-right: 1px solid rgba(148, 163, 184, 0.14); }
.data-table td { border-left: none; border-right: 1px solid rgba(148, 163, 184, 0.1); }
.data-table th:last-child, .data-table td:last-child { border-right: none; }
.data-table tr:last-child td { border-bottom: none; }
.table-sort-btn {
  width: 100%;
  height: auto;
  padding: 0;
  border: none !important;
  background: transparent !important;
  color: inherit !important;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  box-shadow: none !important;
}
.table-sort-btn:hover:not(:disabled),
.table-sort-btn.is-active {
  color: var(--text-main);
}

.pager { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-top: 16px; font-size: 13px; color: var(--text-soft); }
.pager-actions { display: flex; gap: 8px; }
.pager-actions button { height: 36px; padding: 0 12px; }

/* =========================================
   9. MODAIS E BUILDERS
   ========================================= */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.6);
  display: flex; align-items: center; justify-content: center; padding: 8px; z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal {
  width: min(1200px, 100%); max-height: 94vh; overflow: auto;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.modal-header, .modal-footer { padding: 20px 24px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0 0 4px; font-size: 20px; }
.modal-header p { margin: 0; font-size: 14px; color: var(--text-soft); }
.modal-body { padding: 24px; }
.modal-footer { border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--bg-panel-2); }

/* Modais Específicos */
.modal-confirm { width: min(480px, 100%); }
.confirm-modal-message { font-size: 15px; line-height: 1.6; color: var(--text-main); }
.confirm-modal-footer { justify-content: flex-end; }

.modal-status { width: min(520px, 100%); }
.status-modal-body { display: flex; flex-direction: column; gap: 16px; }
.status-progress-track { width: 100%; height: 8px; border-radius: 999px; overflow: hidden; background: var(--border); }
.status-progress-bar { height: 100%; width: 100%; border-radius: 999px; background: var(--primary); transition: width 0.25s ease, opacity 0.25s ease; }
.status-progress-bar.is-indeterminate { width: 40%; animation: status-indeterminate 1.2s ease-in-out infinite; }
.status-progress-bar.is-complete { width: 100%; animation: none; background: #10b981; }
.status-progress-bar.is-error { width: 100%; animation: none; background: var(--danger); }
.status-modal-message { font-size: 14px; color: var(--text-main); line-height: 1.5; }
@keyframes status-indeterminate { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }

/* Builder Form e Assistentes */
.modal-builder-fullscreen {
  width: calc(98vw / var(--app-ui-zoom));
  max-width: calc(98vw / var(--app-ui-zoom));
  height: calc(98vh / var(--app-ui-zoom));
  max-height: calc(98vh / var(--app-ui-zoom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  zoom: 1;
}
.modal-builder-fullscreen .modal-body { flex: 1; overflow: hidden; padding: 0; }
.builder-layout-split { display: grid; grid-template-columns: minmax(720px, 44%) minmax(0, 1fr); height: 100%; }
.builder-config-panel { padding: 24px 26px 22px; overflow-y: auto; border-right: 1px solid var(--border); }
.builder-preview-panel { padding: 18px 22px 22px; background: var(--bg-panel-2); display: flex; flex-direction: column; overflow: hidden; }
.preview-header { font-size: 13px; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 16px; }
.preview-content-area { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px; overflow: hidden; box-shadow: var(--shadow); }
.live-preview-container { width: 100%; height: 100%; min-height: 400px; }

/* Tabs Builder */
.builder-tabs { display: flex; gap: 8px; border-bottom: 2px solid var(--border); margin-bottom: 24px; }
.builder-tab-btn { background: transparent; border: none; color: var(--text-soft); cursor: pointer; padding: 10px 16px; font-size: 14px; font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -2px; border-radius: 8px 8px 0 0; }
.builder-tab-btn:hover { background: rgba(59, 130, 246, 0.05); color: var(--text-main); }
.builder-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.builder-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-head-grid { grid-template-columns: 1fr 1fr 220px; }
.builder-section { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--border); }
.no-border-top { border-top: 0; padding-top: 0; margin-top: 0; }
.section-title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.section-actions-inline { display: none; }
.builder-assist-grid { display: grid; gap: 16px; }
.builder-assist-grid-2cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.helper-title, .metric-assist-title { font-size: 13px; font-weight: 700; color: var(--text-soft); margin-bottom: 8px; }
.assist-search { margin-bottom: 8px; }
.assist-list { min-height: 104px; max-height: 200px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: var(--bg-panel-2); }
.builder-formula-blocks { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: grid; gap: 12px; }
.builder-formula-block-header { font-size: 13px; font-weight: 700; color: var(--text-main); }
.builder-formula-block-row { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; align-items: center; }
.builder-formula-block-args { display: grid; gap: 12px; }
.formula-block-arg,
.formula-block-condition { display: grid; gap: 8px; }
.formula-condition-row { display: grid; grid-template-columns: 1.2fr 0.8fr 1fr; gap: 8px; }
.builder-formula-preview { background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.builder-formula-preview-label { font-size: 12px; color: var(--text-soft); margin-bottom: 6px; }
.builder-formula-preview-text { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 14px; color: var(--text-main); white-space: pre-wrap; word-break: break-word; }
.builder-formula-preview .formula-apply-btn { margin-top: 10px; }
.builder-formula-validation { min-height: 18px; font-size: 12px; color: var(--text-soft); }
.builder-formula-validation.is-error { color: var(--danger); }
.builder-formula-validation.is-warning { color: #f59e0b; }
.builder-formula-validation.is-success { color: #059669; }
.formula-block-note { font-size: 12px; color: var(--text-soft); }
.formula-block-button-row { display: flex; gap: 8px; margin-top: 12px; }
.formula-apply-btn { background: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px; }
.formula-apply-btn:hover { background: var(--primary-dark, #1d4ed8); }
.builder-metric-formula {
    width: 100%;
    min-height: 120px;
    max-height: 260px;
    resize: vertical;
    padding: 12px 14px;
    border: 1px solid var(--input-border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-main);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow: auto;
  }
  .builder-metric-formula:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.15);
  }
.chips-wrap { display: flex; gap: 8px; flex-wrap: wrap; }
.selector-chip { border: 1px solid transparent; background: var(--primary); color: #fff; border-radius: 6px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }

/* Métricas internas */
.metric-card { background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.metric-card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.metric-card-title { font-size: 16px; font-weight: 700; }
.metric-main-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.metric-main-grid .field-span-2 { grid-column: span 2; }
.metric-color-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.metric-boolean-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: end; }
.checkbox-inline { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 4px; cursor: pointer; }
.checkbox-inline input { width: auto; min-height: auto; cursor: pointer; }
.metric-assist-block { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.metric-category-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.metric-category-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-panel); }
.metric-category-name { min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.metric-category-row input[type="color"] { width: 44px; min-width: 44px; height: 32px; padding: 2px; }
.kpi-builder-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.kpi-format-grid { display: grid; grid-template-columns: 1fr 180px; gap: 16px; }
.special-chart-panel { display: grid; gap: 18px; }
.special-chart-panel-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.special-chart-panel-title { margin: 0; font-size: 16px; font-weight: 700; color: var(--text-main); }
.special-chart-panel-subtitle { font-size: 12px; color: var(--text-soft); line-height: 1.5; }
.special-chart-steps { display: grid; gap: 12px; }
.special-chart-step {
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  border-radius: 12px;
  padding: 14px;
  display: grid;
  gap: 12px;
}
.special-chart-step-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.special-chart-step-header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.special-chart-step-title { font-size: 13px; font-weight: 700; color: var(--text-main); }
.special-chart-step-body { display: grid; gap: 12px; }
.special-chart-step.is-collapsed .special-chart-step-body { display: none; }
.special-chart-step-summary {
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 420px;
}
.special-chart-inline-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.special-chart-inline-grid > .field.field-span-all { grid-column: 1 / -1; min-width: 0; }
.special-chart-inline-grid-3 { display: grid; grid-template-columns: 1.2fr 1fr 90px; gap: 12px; }
.special-step-label-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.06);
}
.special-step-label-panel .field {
  min-width: 0;
}
.special-step-formula-wrap,
#builderWaterfallFormulaBlocks {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
}
.special-step-formula-wrap .builder-formula-blocks,
#builderWaterfallFormulaBlocks.builder-formula-blocks {
  width: 100%;
}
.special-chart-empty-note {
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--text-soft);
  font-size: 12px;
}
.special-chart-item-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 4px 2px;
}
.special-chart-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-main);
}
.special-chart-dimension-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-panel-2);
}
.special-chart-dimension-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}
.special-chart-dimension-toggle {
  min-width: 0;
}
.special-chart-dimension-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}
.special-chart-dimension-value {
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
  font-weight: 700;
}
.special-chart-dimension-config {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 10px;
  grid-column: 1 / 2;
}
.special-chart-dimension-actions {
  display: flex;
  gap: 4px;
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  align-self: center;
}
.special-chart-dimension-actions button {
  width: 34px;
  height: 32px;
  padding: 0;
}
.special-chart-dimension-list {
  gap: 10px;
}
.special-chart-summary-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-panel-2);
}
.special-chart-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-main);
}
.special-chart-summary-row strong {
  white-space: nowrap;
}
.special-chart-summary-row.is-total {
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-weight: 700;
}
.special-chart-advanced-panel {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--bg-panel-2);
}
.special-chart-advanced-panel summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
}
.special-chart-help-compact {
  margin-top: 6px;
  padding: 8px 10px;
}
.special-chart-dimension-controls {
  align-items: end;
}
@media (max-width: 1200px) {
  .special-step-label-panel {
    grid-template-columns: 1fr;
  }
  .modal-builder-fullscreen { width: 100vw; max-width: 100vw; height: 100vh; border-radius: 0; zoom: 1; }
  .builder-layout-split { grid-template-columns: 1fr; }
  .special-chart-dimension-item {
    grid-template-columns: 1fr;
  }
  .special-chart-dimension-config {
    grid-template-columns: 1fr;
    grid-column: auto;
  }
  .special-chart-dimension-actions {
    grid-column: auto;
    grid-row: auto;
    justify-content: flex-start;
  }
}
.special-step-formula-blocks.is-disabled {
  opacity: 0.5;
  pointer-events: none;
}
.special-step-formula-wrap { display: grid; gap: 10px; }
.special-chart-help {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  color: var(--text-soft);
  background: var(--bg-panel-2);
  font-size: 12px;
  line-height: 1.5;
}
.special-chart-order-textarea { min-height: 110px; resize: vertical; }

/* =========================================
   10. MENU DE PROJETOS (SALVAR/ABRIR)
   ========================================= */
.projects-menu { position: relative; }
.projects-menu-btn { min-width: 108px; }
.projects-menu-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); width: 360px; max-width: min(90vw, 360px);
  padding: 20px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); z-index: 120; display: flex; flex-direction: column; gap: 16px;
}
.projects-menu-title { font-size: 18px; font-weight: 700; }
.projects-menu-subtitle { font-size: 13px; color: var(--text-soft); line-height: 1.4; }
.projects-menu-field { margin-bottom: 0; }
.project-current-info {
  min-height: 44px; border: 1px solid var(--border); background: var(--bg-panel-2);
  border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--text-main); display: flex; align-items: center;
}

.modal-projects { width: min(900px, 100%); }
.compact-projects-modal .modal-body { padding-top: 16px; }
.projects-table-wrap { max-height: 52vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-panel); }
.projects-table { width: 100%; border-collapse: collapse; }
.projects-table td, .projects-table th { vertical-align: middle; padding: 12px 16px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px;}
.projects-table th { background: var(--bg-panel-2); font-weight: 600; color: var(--text-soft); }
.project-actions-inline { display: flex; gap: 8px; flex-wrap: wrap; }
.project-actions-inline button { height: 36px; padding: 0 12px; font-size: 13px; }
.project-empty-row td { color: var(--text-soft); text-align: center; padding: 32px 16px; }
.projects-footer-text { font-size: 13px; color: var(--text-soft); }
code { background: var(--bg-panel); border: 1px solid var(--border); padding: 2px 6px; border-radius: 6px; font-family: monospace; font-size: 12px; }

/* =========================================
   11. CONTROLES DE ESTADO E RESPONSIVIDADE
   ========================================= */
/* Colapso da Sidebar */
.app-shell.sidebar-collapsed { grid-template-columns: minmax(0, 1fr) !important; }
.app-shell.sidebar-collapsed .sidebar { display: none !important; }
.app-shell.sidebar-collapsed .content { grid-column: 1 / -1; width: 100%; max-width: 100%; min-width: 0; }
.app-shell.sidebar-collapsed .topbar-panel,
.app-shell.sidebar-collapsed .panel,
.app-shell.sidebar-collapsed #kpisContainer,
.app-shell.sidebar-collapsed #analysisContainer { width: 100%; max-width: 100%; min-width: 0; }
.hamburger-btn { font-size: 22px; }

@media (max-width: 1100px) {
  body { zoom: 1; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); padding: 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 24px; }
  .sidebar .panel { padding: 0; }
}

@media (max-width: 980px) {
  body { zoom: 1; }
  #kpisContainer, #analysisContainer, .builder-grid, .chart-head-grid, .builder-assist-grid-2cols, .metric-main-grid, .metric-color-grid, .metric-boolean-row, .metric-category-grid, .kpi-builder-grid, .kpi-format-grid {
    grid-template-columns: 1fr;
  }
  .field-span-2 { grid-column: span 1 !important; }
  .span-nano, .span-micro, .span-small, .span-medium, .span-large, .span-full { grid-column: 1 / -1; }
  .topbar { flex-direction: column; }
  .modal-footer { flex-direction: column-reverse; align-items: stretch; text-align: center; }
  .confirm-modal-footer { flex-direction: row; justify-content: space-between; }
  .dashboard-title-input { font-size: 24px; }
  .topbar h1 { font-size: 24px; }
  .projects-menu-dropdown { width: min(96vw, 360px); }
  .dashboard-title-row, .dashboard-description-row { align-items: center; }
  .sidebar { grid-template-columns: 1fr; }
}
/* =========================================
   AJUSTES FINAIS: DARK MODE E GHOST BUTTONS
   ========================================= */

/* 1. Remove o azul maciço dos botões no Dark Mode,
      deixando TODOS com o estilo do "Limpar Filtros" */
body.theme-dark button {
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--border);
}

body.theme-dark button:hover:not(:disabled) {
  background: var(--bg-panel-2);
}

body.theme-dark .dashboard-tab-btn.is-active,
.dashboard-tab-btn.is-active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* Garante que os botões de perigo (vermelhos) ainda mantenham a cor original */
body.theme-dark button.danger {
  background: var(--danger);
  color: #ffffff;
  border-color: transparent;
}
body.theme-dark button.danger:hover:not(:disabled) {
  background: #dc2626;
}


/* =========================================
   12. FILTROS E SELETORES
   ========================================= */

/* Container principal dos filtros */
#filtersContainer {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Linha de filtro individual */
.filter-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

/* Combobox para seleção de coluna */
.filter-combobox {
  position: relative;
  width: 100%;
  min-width: 0;
}

.filter-column-display {
  width: 100%;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-main);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
  text-align: left;
}

.filter-column-display:hover,
.filter-column-display:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  background: var(--bg-panel-2);
}

body.theme-dark .filter-column-display:hover,
body.theme-dark .filter-column-display:focus {
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.25);
}

.filter-column-selector {
  position: relative;
}

.filter-column-search {
  width: 100%;
  min-height: 42px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-main);
  padding: 10px 14px;
  font-size: 14px;
}

.filter-column-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.15);
}

.filter-column-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 100;
  display: none;
}

.filter-column-dropdown.show {
  display: block;
}

.searchable-select-wrapper {
  position: relative;
  width: 100%;
  min-width: 0;
}

.searchable-select-wrapper select {
  display: none;
}

.searchable-select-display {
  width: 100%;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-main);
  cursor: pointer;
  text-align: left;
}

.searchable-select-display.empty {
  color: var(--text-soft);
}

.searchable-select-display:hover,
.searchable-select-display:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  background: var(--bg-panel-2);
}

.searchable-select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow: hidden;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 200;
  display: none;
}

.searchable-select-dropdown.show {
  display: block;
}

.searchable-select-search {
  width: 100%;
  min-height: 42px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-main);
  padding: 10px 14px;
  font-size: 14px;
}

.searchable-select-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.15);
}

.searchable-select-list {
  max-height: 260px;
  overflow-y: auto;
}

.searchable-select-option {
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  display: block;
}

.searchable-select-option:hover,
.searchable-select-option:focus {
  background: var(--bg-panel-2);
  outline: none;
}

.searchable-select-option.active {
  background: rgba(59, 130, 246, 0.12);
  color: var(--primary);
}

.searchable-select-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-soft);
  font-size: 13px;
}
.filter-column-option:focus {
  background: var(--bg-panel-2);
  outline: none;
}

.filter-column-option:last-child {
  border-bottom: none;
}

.filter-column-option:hover {
  background: var(--bg-panel-2);
}

.filter-column-option.selected {
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary);
}

/* Badge de tipo de coluna */
.column-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.badge-string {
  background: #10b981;
  color: #ffffff;
}

.badge-number {
  background: #f59e0b;
  color: #ffffff;
}

.badge-date {
  background: #8b5cf6;
  color: #ffffff;
}

/* Estado vazio do dropdown */
.filter-column-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-soft);
  font-size: 13px;
}

/* Painel de valores de filtro */
.filter-values-panel {
  position: relative;
  width: 100%;
  min-width: 0;
  max-height: 360px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.filter-values-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  padding: 16px;
  color: var(--text-soft);
  text-align: center;
  font-size: 13px;
}

.filter-row-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.filter-remove-btn {
  width: auto;
  min-width: 96px;
  padding: 0 14px;
  height: 44px;
}

.filter-selected-info {
  padding: 10px 14px;
}

/* Chips dos valores selecionados */
.filter-selected-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  align-items: center;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--primary);
  color: #ffffff;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}

.filter-chip-remove {
  background: none;
  border: none;
  color: #ffffff;
  cursor: pointer;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  opacity: 0.8;
  transition: opacity 0.15s;
}

.filter-chip-remove:hover {
  opacity: 1;
}

/* Campo de busca nos valores */
.filter-values-search {
  width: 100%;
  min-height: 40px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text-main);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
}

.filter-values-search::placeholder {
  color: var(--text-soft);
}

/* Lista de valores */
.filter-values-list {
  flex: 1;
  overflow-y: auto;
  max-height: 250px;
}

.filter-value-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background-color 0.15s;
}

.filter-value-item:last-child {
  border-bottom: none;
}

.filter-value-item:hover {
  background: var(--bg-panel-2);
}

.filter-value-item.selected {
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary);
}

.filter-value-item input[type="checkbox"] {
  width: auto;
  min-height: auto;
  cursor: pointer;
  margin: 0;
}

/* Informações sobre seleção */
.filter-selected-info {
  padding: 8px 12px;
  background: var(--bg-panel-2);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-soft);
  text-align: center;
}

/* Botão de remover filtro */
.filter-remove-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 20px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.filter-remove-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-color: var(--danger);
}

/* Responsividade para filtros */
@media (max-width: 980px) {
  .filter-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .filter-combobox,
  .filter-values-panel {
    min-width: auto;
    flex: none;
  }

  .filter-remove-btn {
    align-self: flex-end;
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}
      no modo escuro, ficando idêntico à lixeira */
body.theme-dark .card-actions button.secondary,
body.theme-dark .inline-edit-btn {
  background: transparent !important;
  border-color: transparent !important;
  color: var(--text-soft) !important;
}

body.theme-dark .card-actions button.danger {
  background: transparent !important;
  border-color: transparent !important;
  color: var(--text-soft) !important;
}

body.theme-dark .card-actions button.secondary:hover,
body.theme-dark .inline-edit-btn:hover {
  background: rgba(148, 163, 184, 0.15) !important;
  color: var(--text-main) !important;
}

body.theme-dark .card-actions button.danger:hover {
  background: rgba(239, 68, 68, 0.15) !important;
  color: var(--danger) !important;
}

/* Metric Card Tabs */
.metric-tabs-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.metric-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft);
  cursor: pointer;
  transition: all 0.2s;
}
.metric-tab-btn:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}
.metric-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
