/* ===== VARIÁVEIS ===== */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #dde1e7;
  --primary: #1a6faf;
  --primary-dk: #145c92;
  --success: #1e8a3e;
  --danger: #c0392b;
  --warning: #e67e22;
  --text: #1a1d23;
  --muted: #5a6270;
  --shadow: 0 1px 4px rgba(0,0,0,.10);
  --radius: 6px;
}

/* ===== BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }

/* ===== HEADER ===== */
header { background: var(--primary); color: #fff; padding: .65rem 1.5rem; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 6px rgba(0,0,0,.18); }
header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: .02em; display: flex; align-items: baseline; gap: .5rem; }
.app-subtitle { font-size: .7rem; font-weight: 400; opacity: .65; letter-spacing: .04em; text-transform: uppercase; }
header nav a { color: rgba(255,255,255,.85); text-decoration: none; font-size: .85rem; margin-left: 1.25rem; }
header nav a:hover { color: #fff; }

/* ===== MAIN ===== */
main { max-width: 1160px; margin: 0 auto; padding: 1.25rem 1.5rem 3rem; }
main.main-fullwidth { max-width: none; padding-left: 1.25rem; padding-right: 1.25rem; }

/* ===== ALERTS ===== */
.alert { padding: .85rem 1.1rem; border-radius: var(--radius); margin-bottom: 1.2rem; font-size: .9rem; }
.alert-error { background: #fde8e8; border: 1px solid #f5b7b1; color: #7b241c; }
.alert-warning { background: #fef9ec; border: 1px solid #f5cba7; color: #784212; }
.alert ul { margin: .35rem 0 0 1.2rem; }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem 1rem; border: none; border-radius: var(--radius); cursor: pointer; font-size: .85rem; font-weight: 600; text-decoration: none; transition: filter .15s; line-height: 1.4; }
.btn:hover { filter: brightness(.9); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #6b7280; color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-lg { padding: .55rem 1.5rem; font-size: .95rem; }
.btn-add { background: none; border: 1px dashed var(--primary); color: var(--primary); border-radius: var(--radius); padding: .25rem .7rem; cursor: pointer; font-size: .82rem; margin-top: .3rem; }
.btn-add:hover { background: var(--primary); color: #fff; }
.btn-remove { background: none; border: 1px solid var(--danger); color: var(--danger); border-radius: var(--radius); padding: .15rem .45rem; cursor: pointer; font-size: .78rem; }
.btn-remove:hover { background: var(--danger); color: #fff; }

/* ===== FORM SECTIONS ===== */
.form-section { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.1rem; overflow: hidden; }
.section-toggle { padding: .65rem 1.1rem; font-size: .95rem; font-weight: 700; background: #f4f6f9; border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; display: flex; justify-content: space-between; align-items: center; }
.section-toggle::after { content: "▲"; font-size: .7rem; color: var(--muted); transition: transform .2s; }
.form-section.collapsed .section-toggle::after { transform: rotate(180deg); }
.form-section.collapsed .form-section-body { display: none; }
.form-section-body { padding: 1.1rem 1.25rem; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .85rem; }
.form-group { display: flex; flex-direction: column; gap: .25rem; }
.form-group label { font-weight: 600; font-size: .8rem; color: var(--muted); min-height: 2.25rem; display: flex; align-items: flex-end; }
.form-group input[type=number], .form-group input[type=text], .form-group select {
  border: 1px solid var(--border); border-radius: var(--radius); padding: .38rem .6rem;
  font-size: .9rem; width: 100%; background: #fff; transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(26,111,175,.15); }
.form-group small { color: var(--muted); font-size: .76rem; line-height: 1.3; }
.form-group textarea { border: 1px solid var(--border); border-radius: var(--radius); padding: .38rem .6rem; font-size: .9rem; width: 100%; background: #fff; resize: vertical; font-family: inherit; transition: border-color .15s; }
.form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(26,111,175,.15); }
.form-group--descricao { grid-column: 1 / -1; }
.text-warning { color: var(--warning); font-size: .78rem; }

.checkbox-label { display: flex; align-items: center; gap: .45rem; cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--text); margin-top: 1.3rem; }
.checkbox-label input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); }

.section-hr { border: none; border-top: 1px solid var(--border); margin: .9rem 0; }
.sub-title { font-size: .9rem; font-weight: 700; margin-bottom: .7rem; color: var(--text); }
.variation-section { margin-top: .9rem; }
.variation-label { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .4rem; }
.variation-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; flex-wrap: wrap; }
.variation-row input { flex: 1; min-width: 0; }
.variation-row .var-label { font-size: .78rem; color: var(--muted); white-space: nowrap; }

/* Valorização params */
.val-params { margin-top: .75rem; padding: .75rem; background: #f8f9fb; border-radius: var(--radius); border: 1px solid var(--border); }

/* Form actions bar */
.form-actions-bar { display: flex; align-items: center; gap: .75rem; padding: 1rem 0; flex-wrap: wrap; }
.form-actions-hint { color: var(--muted); font-size: .82rem; }

/* ===== RESULTS HEADER ===== */
.results-header { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: .85rem 1.25rem; margin-bottom: 1.1rem; display: flex; flex-direction: column; gap: .6rem; }
.results-nome { display: flex; align-items: center; gap: .5rem; font-size: 1rem; border-bottom: 1px solid var(--border); padding-bottom: .5rem; }
.results-nome-label { color: var(--muted); font-size: .85rem; }
.results-nome strong { color: var(--primary); font-size: 1.05rem; }
.results-descricao { font-size: .83rem; color: var(--muted); font-style: italic; padding-bottom: .3rem; border-bottom: 1px solid var(--border); }
.results-header-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .7rem; }
.results-summary { display: flex; gap: 1.5rem; flex-wrap: wrap; font-size: .85rem; }
.results-summary span { color: var(--muted); }
.results-summary strong { color: var(--text); }
.results-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
/* Pressupostos da simulação */
.pressupostos-details { margin-top: .75rem; border-top: 1px solid var(--border); padding-top: .5rem; }
.pressupostos-summary { font-size: .8rem; color: var(--muted); cursor: pointer; user-select: none; list-style: none; display: inline-flex; align-items: center; gap: .4rem; }
.pressupostos-summary::before { content: '▶'; font-size: .65rem; transition: transform .15s; }
details[open] .pressupostos-summary::before { transform: rotate(90deg); }
.pressupostos-grid { display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; margin-top: .6rem; }
.pressuposto-item { display: flex; flex-direction: column; min-width: 180px; }
.pressuposto-label { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.pressuposto-valor { font-size: .82rem; font-weight: 600; color: var(--text); }
/* Nome da simulação no formulário */
.form-section--nome { background: var(--primary-light, #eef4ff); border-left: 4px solid var(--primary); }
.form-group--nome { max-width: 480px; }
.form-group--nome label { font-size: .8rem; font-weight: 600; color: var(--primary); }
/* Secção opcional */
.form-section--opcional { border-left: 4px solid var(--warning); }
.opcional-badge { font-size: .7rem; font-weight: 600; background: var(--warning); color: #fff; border-radius: 3px; padding: .1rem .4rem; vertical-align: middle; margin-left: .5rem; }
/* Subsecção dentro de uma secção opcional */
.subsection-title { font-size: 1rem; font-weight: 600; color: var(--primary); margin: 1.4rem 0 .6rem; padding-top: .2rem; }

/* ===== RESULTS TABLE ===== */
#resultados-container { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.results-table { width: 100%; border-collapse: collapse; }
.results-table thead th { background: var(--primary); color: #fff; padding: .55rem .75rem; text-align: right; font-size: .8rem; font-weight: 700; border-right: 1px solid rgba(255,255,255,.15); }
.results-table thead th:first-child { text-align: center; }
.results-table thead th:last-child { border-right: none; }

.year-header { cursor: pointer; transition: background .12s; }
.year-header:hover { background: #eef3fb; }
.year-header.active { background: #dce8f7; }
.year-header td { padding: .45rem .75rem; border-bottom: 1px solid var(--border); text-align: right; font-size: .87rem; }
.year-header td:first-child { text-align: center; }
.year-header .toggle-cell { color: var(--primary); font-size: .7rem; transition: transform .2s; }
.year-header.active .toggle-cell { transform: rotate(180deg); }
.has-events td:first-child { border-left: 3px solid var(--warning); }

.saldo-positivo { color: var(--success); font-weight: 700; }
.saldo-negativo { color: var(--danger); font-weight: 700; }

/* ===== YEAR DETAILS ===== */
.year-details { display: none; background: #f7f9fc; }
.year-details.open { display: table-row; }
.year-details-inner { padding: 1.1rem 1.25rem; }

.detail-tables { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; margin-bottom: 1.1rem; }
@media (max-width: 780px) { .detail-tables { grid-template-columns: 1fr; } }

.detail-table { width: 100%; border-collapse: collapse; font-size: .83rem; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.detail-table caption { font-weight: 700; font-size: .84rem; text-align: left; padding: .45rem .65rem; background: #e8edf5; }
.detail-table td { padding: .28rem .65rem; border-bottom: 1px solid #eff1f5; }
.detail-table td:last-child { text-align: right; font-weight: 600; }
.detail-table .total-row td { background: #f0f4fb; font-weight: 700; }
.detail-table hr { border: none; border-top: 1px solid #dde1e7; }

/* ===== EVENTS PANEL ===== */
.events-panel { background: #fffbf0; border: 1px solid #f0d060; border-radius: var(--radius); padding: .9rem 1rem; }
.events-panel h4 { font-size: .88rem; font-weight: 700; color: #7a5c00; margin-bottom: .7rem; }
.events-checkboxes { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin-bottom: .75rem; }
.events-inputs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .65rem; align-items: end; }
.event-group { display: flex; flex-direction: column; gap: .2rem; }
.event-group label { font-size: .78rem; font-weight: 600; color: var(--muted); }
.event-group input[type=number] { border: 1px solid var(--border); border-radius: var(--radius); padding: .3rem .5rem; font-size: .85rem; background: #fff; }
.event-group.checkbox-group { flex-direction: row; align-items: center; gap: .4rem; }
.event-group.checkbox-group label { font-size: .85rem; font-weight: 600; color: var(--text); cursor: pointer; }
.event-group.checkbox-group input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.events-form-actions { margin-top: .7rem; display: flex; align-items: center; gap: .7rem; }
.event-feedback { font-size: .82rem; font-weight: 600; }

/* ===== BADGES ===== */
.event-badge { display: inline-block; background: #f0d060; color: #7a5c00; border-radius: 3px; padding: 0 4px; font-size: .65rem; font-weight: 800; margin-left: 3px; vertical-align: middle; }
.event-badge--rnd { background: #b8e0ff; color: #1a4f7a; }
.event-badge--ano0 { background: #c8e6c9; color: #2e7d32; }
.year-0-header { border-top: 2px solid var(--primary); }
.year-0-header td { font-style: italic; color: var(--muted); }
.year-0-header td:first-child, .year-0-header td:nth-last-child(2), .year-0-header td:last-child { font-style: normal; color: inherit; }

/* ===== LEGENDA BADGES ===== */
.badge-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .55rem 1rem;
  margin-bottom: 1rem;
  font-size: .82rem;
  color: var(--muted);
}
.badge-legend__title { font-weight: 700; color: var(--text); margin-right: .25rem; }
.badge-legend__item { display: flex; align-items: center; gap: .3rem; white-space: nowrap; }
.badge-legend__item .event-badge { margin-left: 0; }

/* ===== MODALS ===== */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 900; justify-content: center; align-items: center; }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 1.5rem; width: min(92%, 420px); box-shadow: 0 6px 24px rgba(0,0,0,.22); }
.modal h3 { font-size: 1.05rem; margin-bottom: 1rem; }
.modal input[type=text] { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .65rem; font-size: .92rem; margin-bottom: .75rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; }

/* ===== SIMULATIONS LIST ===== */
.sim-list { list-style: none; max-height: 280px; overflow-y: auto; margin-bottom: .85rem; border: 1px solid var(--border); border-radius: var(--radius); }
.sim-list li { padding: .4rem .75rem; border-bottom: 1px solid #eee; font-size: .88rem; }
.sim-list li:last-child { border-bottom: none; }
.sim-list li a { color: var(--primary); text-decoration: none; font-weight: 600; }
.sim-list li a:hover { text-decoration: underline; }

/* ===== APP INTRO ===== */
.app-intro { background: var(--surface); border-left: 4px solid var(--primary); border-radius: var(--radius); padding: .75rem 1.1rem; margin-bottom: 1.4rem; color: var(--text); font-size: .92rem; line-height: 1.5; }

/* ===== FOOTER / DISCLAIMER ===== */
.app-footer { margin-top: 2.5rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border); }
.app-disclaimer { font-size: .78rem; color: #888; line-height: 1.55; text-align: center; max-width: 820px; margin: 0 auto; }

/* ===== BOTÃO SM ===== */
.btn-sm { padding: .25rem .6rem; font-size: .78rem; }
.btn-danger { background: var(--danger); color: #fff; }

/* ===== COMPARADOR ===== */
.compare-page-header { margin-bottom: 1.1rem; }
.compare-page-header h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: .3rem; }
.compare-intro-text { font-size: .88rem; color: var(--muted); line-height: 1.5; }

/* Container de colunas: scroll horizontal quando há muitas simulações */
#compare-container {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 1rem;
}

/* Cada coluna de simulação */
.sim-col {
  flex: 1 1 600px;   /* cresce para preencher o espaço, mínimo 600px */
  min-width: 560px;
  max-width: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sim-col-loading {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .9rem;
}

.sim-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .9rem;
  background: #f4f6f9;
  border-bottom: 1px solid var(--border);
  gap: .5rem;
}

.sim-col-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sim-col-actions { display: flex; gap: .35rem; flex-shrink: 0; }

/* A tabela de resultados dentro de uma coluna */
.compare-results-table { width: 100%; }
.sim-col-results { overflow-x: auto; }

/* Botão de adicionar coluna */
.sim-col-add {
  flex: 0 0 auto;
  width: 160px;
  min-height: 200px;
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s;
  align-self: stretch;
}

.sim-col-add:hover { background: #eef4ff; }

.sim-col-add-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  color: var(--primary);
  font-size: .88rem;
  font-weight: 600;
  pointer-events: none;
}

.sim-col-add-icon { font-size: 2rem; line-height: 1; }

/* Dica quando não há colunas */
.compare-empty-hint {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.7;
}

