:root {
  --planilha-grid-color: #e0e0e0;
  --planilha-outline-color: #1890ff;
  --planilha-font-color: #262626;
  --planilha-header-bg: #f5f5f5;
  --planilha-header-text: #595959;
  --planilha-header-border: #d9d9d9;
}

.visual-builder-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: #fff;
  overflow: hidden;
}

.vb-toolbar {
  height: 48px;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  padding: 0 16px;
  flex-shrink: 0;
}

.vb-toolbar .toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.vb-toolbar .toolbar-group button {
  border: none;
  background: transparent;
  box-shadow: none;
  color: #595959;
  cursor: pointer;
  padding: 4px 8px;
}

.vb-toolbar .toolbar-group button:hover {
  background: #e6e6e6;
  color: #000;
  border-radius: 4px;
}

.vb-toolbar .toolbar-divider {
  width: 1px;
  height: 24px;
  background: #d9d9d9;
  margin: 0 12px;
}

.vb-formula-bar {
  height: 32px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #e0e0e0;
  background: #fff;
  padding: 0 8px;
  flex-shrink: 0;
}

.vb-formula-bar .cell-address {
  width: 40px;
  font-size: 12px;
  font-weight: 600;
  color: #595959;
  text-align: center;
  border-right: 1px solid #e0e0e0;
  margin-right: 8px;
  user-select: none;
}

.vb-formula-bar .formula-icon {
  color: #8c8c8c;
  font-style: italic;
  font-weight: bold;
  margin-right: 8px;
  user-select: none;
}

.vb-formula-bar .formula-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 13px;
  height: 100%;
  color: #000;
  width: 100%;
}

.vb-grid {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.vb-grid .spreadsheet-wrapper {
  width: 100%;
  height: 100%;
  overflow: auto;
}

.vb-grid table {
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 100%;
}

.vb-grid th, .vb-grid td {
  border: 1px solid var(--planilha-grid-color);
  padding: 0;
  min-width: 100px;
  height: 24px;
  box-sizing: border-box;
}

.vb-grid thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--planilha-header-bg);
  user-select: none;
}

.vb-grid thead th {
  background: var(--planilha-header-bg);
  font-weight: 600;
  color: var(--planilha-header-text);
  font-size: 12px;
  text-align: center;
  border-bottom: 2px solid var(--planilha-header-border);
  cursor: pointer;
  position: relative;
}

.vb-grid thead th:hover {
  background: #e6e6e6;
}

.vb-grid thead .row-header-corner {
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  background: var(--planilha-header-bg);
  position: sticky;
  left: 0;
  z-index: 20;
  cursor: default;
}

.vb-grid .row-header {
  background: var(--planilha-header-bg);
  font-weight: 600;
  color: var(--planilha-header-text);
  font-size: 12px;
  text-align: center;
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  position: sticky;
  left: 0;
  z-index: 5;
  border-right: 2px solid var(--planilha-header-border);
  cursor: pointer;
  user-select: none;
}

.vb-grid .row-header:hover {
  background: #e6e6e6;
}

.vb-grid td:not(.row-header) {
  background: #fff;
  font-size: 13px;
  color: var(--planilha-font-color);
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  cursor: cell;
  user-select: none;
  position: relative;
}

.vb-grid td:not(.row-header).selected {
  outline: 2px solid var(--planilha-outline-color);
  z-index: 2;
}

.vb-grid td:not(.row-header).in-range {
  border: none !important;
  box-shadow: inset 0 0 0 1px var(--planilha-outline-color) !important;
  z-index: 1;
}

.vb-grid td .cell-editor {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  padding: 0;
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  background: transparent;
  color: inherit;
  position: absolute;
  top: 0;
  left: 0;
  padding: 2px 4px;
}

.resize-handle-col {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 20;
}

.resize-handle-col:hover {
  background-color: var(--planilha-outline-color);
}

.resize-handle-row {
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 6px;
  cursor: row-resize;
  z-index: 20;
}

.resize-handle-row:hover {
  background-color: var(--planilha-outline-color);
}

.sim-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
  background: var(--simulador-bg, #f4f6fa);
  color: var(--simulador-text-color, #1e293b);
  font-family: var(--font-name, "Rajdhani"), sans-serif;
}

.sim-body {
  display: flex;
  flex: 1 1 auto;
  width: 100%;
  gap: 0;
  min-height: 0;
}

.sim-topo {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.sim-kpi-strip {
  flex: 1 1 auto;
  display: flex;
  gap: 0;
  padding: 2px 2px;
  min-width: 0;
}

.sim-kpi-strip-item {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2px 2px;
}

.sim-kpi-par {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 6px 10px;
}

.sim-kpi-par + .sim-kpi-par {
  border-left: 1px solid rgba(30, 58, 95, 0.12);
}

.sim-kpi-par .sim-kpi-strip-item {
  flex: 0 0 auto;
  padding: 0;
}

.sim-kpi-strip-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--simulador-heading-color, #1e3a5f);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.sim-kpi-strip-valor {
  font-size: clamp(14px, 1.3vw, 22px);
  font-weight: 700;
  color: var(--simulador-accent-color, #3b82f6);
  line-height: 1.1;
  white-space: nowrap;
}

.sim-kpi-pills {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  justify-content: center;
  min-width: 200px;
}

.sim-esquerda {
  flex: 0 0 60%;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  padding-right: 20px;
}

.sim-divider {
  flex: 0 0 18px;
  position: relative;
  align-self: stretch;
  background: linear-gradient(
    to right,
    transparent calc(50% - 0.5px),
    var(--simulador-border-color, #cbd5e1) calc(50% - 0.5px),
    var(--simulador-border-color, #cbd5e1) calc(50% + 0.5px),
    transparent calc(50% + 0.5px)
  );
}

.sim-divider-chevron {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
  width: 10px;
  height: 10px;
  border-right: 1px solid var(--simulador-border-color, #cbd5e1);
  border-bottom: 1px solid var(--simulador-border-color, #cbd5e1);
  background: var(--simulador-bg, #f4f6fa);
  z-index: 1;
}

.sim-direita {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  padding-left: 20px;
}

.sim-secao {
  background: var(--simulador-panel-bg, #ffffff);
  border-radius: 2px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.sim-secao-titulo {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 16px 0;
  color: var(--simulador-heading-color, #1e3a5f);
}

.sim-campo {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sim-label {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--simulador-label-color, #1e3a5f);
}

.sim-select,
.sim-input {
  height: 36px;
  padding: 4px 10px;
  border: 1px solid var(--simulador-border-color, #cbd5e1);
  border-radius: 2px;
  font-size: 13px;
  background: #fff;
  color: #1e293b;
  outline: none;
  width: 100%;
}

.sim-select:focus,
.sim-input:focus {
  border-color: var(--simulador-accent-color, #3b82f6);
  box-shadow: 0 0 0 2px rgba(59,130,246,.15);
}

.sim-dropdown-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--simulador-border-color, #cbd5e1);
  border-top: none;
  border-radius: 0 0 2px 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 50;
}

.sim-dropdown-item {
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
  color: #1e293b;
}

.sim-dropdown-item:hover {
  background: var(--simulador-accent-color, #3b82f6);
  color: #fff;
}

.sim-dropdown-empty {
  color: #94a3b8;
  cursor: default;
  font-style: italic;
}

.sim-dropdown-empty:hover {
  background: transparent;
  color: #94a3b8;
}

.sim-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.sim-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.sim-btn {
  height: 36px;
  padding: 0 20px;
  border-radius: 2px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.sim-btn-primary {
  background: var(--simulador-btn-bg, #1e3a5f);
  color: #fff;
}

.sim-btn-primary:hover {
  opacity: .9;
}

.sim-btn-secondary {
  background: transparent;
  color: var(--simulador-accent-color, #1e3a5f);
  border-color: var(--simulador-accent-color, #1e3a5f);
}

.sim-btn-secondary:hover {
  background: rgba(30,58,95,.06);
}

.sim-tabela-wrap {
  margin-top: 16px;
  flex: 1 1 auto;
  min-height: 200px;
  max-height: calc(100vh - 425px);
  overflow-y: auto;
  overflow-x: auto;
}

.sim-tabela-header {
  display: flex;
  gap: 0;
  padding: 0 4px 4px;
}

.sim-tabela-header-cell {
  flex: 1 1 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--simulador-heading-color, #1e3a5f);
  padding: 4px 10px;
  white-space: nowrap;
}

.sim-tabela-row {
  display: flex;
  gap: 0;
  align-items: center;
  background: #fff;
  border: 1px solid var(--simulador-border-color, #e2e8f0);
  border-radius: 2px;
  margin-bottom: 6px;
  padding: 2px 4px;
}

.sim-tabela-cell {
  flex: 1 1 0;
  font-size: 13px;
  color: var(--simulador-text-color, #475569);
  padding: 12px 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
}

.sim-remover-btn {
  width: 30px;
  height: 26px;
  border-radius: 2px;
  border: 1px solid var(--simulador-border-color, #cbd5e1);
  background: var(--simulador-panel-bg, #f0f4fa);
  color: var(--simulador-accent-color, #1e3a5f);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.sim-remover-btn:hover {
  background: #fee2e2;
  border-color: #dc2626;
  color: #dc2626;
}

.sim-reset-btn {
  width: 34px;
  height: 34px;
  border-radius: 2px;
  border: 1px solid var(--simulador-border-color, #cbd5e1);
  background: var(--simulador-panel-bg, #f0f4fa);
  color: var(--simulador-accent-color, #1e3a5f);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.sim-reset-btn:hover {
  background: rgba(59,130,246,.08);
  border-color: var(--simulador-accent-color, #3b82f6);
}

.sim-hover-icon {
  cursor: help;
  font-size: 16px;
  line-height: 1;
  color: var(--simulador-accent-color, #3b82f6);
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
}

.sim-hover-icon:hover,
.sim-hover-icon:focus {
  background: rgba(59,130,246,.1);
  outline: none;
}

.sim-hover-popover {
  min-width: 260px;
  background: var(--simulador-panel-bg, #ffffff);
  color: var(--simulador-text-color, #1e293b);
  border: 1px solid var(--simulador-border-color, #e2e8f0);
  border-radius: 2px;
  padding: 8px 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  font-size: 12px;
  text-align: left;
  pointer-events: none;
}

.sim-hover-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 2px 0;
}

.sim-hover-row + .sim-hover-row {
  border-top: 1px dashed var(--simulador-border-color, #e2e8f0);
}

.sim-hover-label {
  font-weight: 600;
  color: var(--simulador-heading-color, #1e3a5f);
}

.sim-hover-val {
  font-weight: 500;
  white-space: nowrap;
}


.sim-direita-baixo {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.sim-resultado-wrap {
  max-height: 280px;
  overflow-y: auto;
  overflow-x: auto;
  border-radius: 3px;
}

.sim-resultado {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.sim-resultado th {
  background: var(--simulador-resultado-header-bg, #1a3550);
  color: var(--simulador-resultado-header-color, #fff);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.sim-resultado td {
  padding: 7px 10px;
  white-space: nowrap;
  color: #1e293b;
  border-bottom: 1px solid #e2e8f0;
}

.sim-resultado tbody tr {
  background: #ffffff;
}

.sim-resultado tbody tr:nth-child(even) {
  background: #f1f5f9;
}

.sim-disclaimer {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.4;
  margin: 0;
  padding: 4px 0;
}


.sim-direita-topo {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sim-titulo {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  color: var(--simulador-heading-color, #1e3a5f);
}

.sim-kpi-card {
  display: flex;
  background: #fff;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
  border: 1px solid var(--simulador-border-color, #e2e8f0);
}

.sim-kpi-gradient {
  flex: 0 0 5px;
  background: linear-gradient(180deg, #1e6091 0%, #3ec6e0 100%);
}

.sim-kpi-content {
  flex: 1 1 auto;
  display: flex;
  padding: 0;
}

.sim-kpi-esquerda {
  flex: 1 1 auto;
  display: flex;
  gap: 0;
}

.sim-kpi-big-item {
  flex: 1 1 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 12px;
}

.sim-kpi-big-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--simulador-heading-color, #1e3a5f);
  margin-bottom: 4px;
}

.sim-kpi-big-valor {
  font-size: 42px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--simulador-accent-color, #3b82f6);
}

.sim-kpi-direita {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px 12px;
  gap: 6px;
  min-width: 180px;
}

.sim-kpi-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: #fff;
  border: 1px solid var(--simulador-border-color, #e2e8f0);
  border-radius: 2px;
  font-size: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.sim-kpi-pill-label {
  font-weight: 600;
  color: var(--simulador-heading-color, #1e3a5f);
  white-space: nowrap;
}

.sim-kpi-pill-valor {
  font-weight: 700;
  white-space: nowrap;
  color: var(--simulador-heading-color, #1e3a5f);
}

.sim-kpi-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  font-family: inherit;
}

.sim-kpi-input:hover {
  border-color: var(--simulador-border-color, #cbd5e1);
  background: rgba(255,255,255,0.5);
}

.sim-kpi-input:focus {
  border-color: var(--simulador-accent-color, #3b82f6);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.sim-kpi-big-valor.sim-kpi-input {
  font-size: 42px;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  width: 100%;
  max-width: 160px;
  padding: 2px 4px;
  color: var(--simulador-accent-color, #3b82f6);
}

.sim-kpi-pill-valor.sim-kpi-input {
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  width: 70px;
  padding: 1px 4px;
}


.sim-direita-meio {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sim-chart-wrap {
  background: var(--simulador-panel-bg, #ffffff);
  border-radius: 2px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.sim-chart-wrap canvas {
  width: 100% !important;
}

@media (max-width: 800px) {
  .sim-container {
    flex-direction: column;
  }
  .sim-esquerda,
  .sim-direita {
    flex: 1 1 auto;
    padding: 0;
  }
  .sim-divider {
    flex: 0 0 1px;
    width: 100%;
    height: 1px;
    margin: 12px 0;
  }
  .sim-kpi-content {
    flex-direction: column;
  }
  .sim-kpi-direita {
    border-top: none;
  }
}
