/* Estilos base e cabeçalho */
:root {
  color-scheme: light;
  font-family: "Segoe UI", Arial, sans-serif;
  color: #233a2e;
  background: #f3f6f2;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: #f3f6f2; }
button, input, select { font: inherit; }
.report-app { width: min(1440px, calc(100% - 40px)); margin: 0 auto; padding: 28px 0 48px; }
.report-header, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.report-header { margin-bottom: 20px; }
.report-header h1, .section-heading h2 { margin: 0; color: #193b2c; }
.report-header h1 { font-size: clamp(1.4rem, 2.4vw, 2rem); }
.report-header p:not(.eyebrow) { margin: 5px 0 0; color: #607568; }
.eyebrow { margin: 0 0 5px; color: #4e7a55; font-size: .72rem; font-weight: 800; letter-spacing: .09em; }
.panel { min-width: 0; margin-bottom: 18px; padding: 20px; border: 1px solid #dce7da; border-radius: 12px; background: #fff; box-shadow: 0 5px 18px rgba(25, 48, 32, .06); }
.section-heading h2 { font-size: 1.08rem; }
.secondary-btn, .primary-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 14px; border: 1px solid #cddbcf; border-radius: 7px; background: #fff; color: #31563d; font-weight: 650; text-decoration: none; cursor: pointer; }
.primary-btn { border-color: #24563a; background: #24563a; color: #fff; }
.secondary-btn:hover { background: #f3f7f2; }
.primary-btn:hover { background: #193f2b; }
button:disabled { opacity: .55; cursor: not-allowed; }
.message { min-height: 1.2em; margin: 10px 0; color: #526b58; font-size: .86rem; }
.message.error { color: #a52f2f; }
.message.success { color: #28643d; }
.save-feedback { margin: 0; padding: 12px 14px; border: 1px solid #c9dfcc; border-radius: 8px; background: #eef7ef; color: #245b34; font-size: .9rem; font-weight: 650; }
.save-feedback.error { border-color: #eccaca; background: #fff2f1; color: #a52f2f; }
.save-feedback[hidden] { display: none; }
/* Tela 1: modelos compartilhados */
.saved-reports { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 12px; }
.saved-report { display: grid; gap: 10px; min-width: 0; padding: 14px; border: 1px solid #dce7da; border-radius: 9px; background: #fbfdfb; }
.saved-report h3 { margin: 0; color: #193b2c; font-size: .98rem; overflow-wrap: anywhere; }
.saved-report p { margin: 0; color: #64786a; font-size: .83rem; line-height: 1.45; }
.saved-report-meta { color: #718075; font-size: .75rem; }
.saved-report-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.saved-report-actions button { min-height: 34px; padding: 6px 10px; font-size: .82rem; }
.empty-state { margin: 0; padding: 16px; border: 1px dashed #cbd9cb; border-radius: 8px; color: #718075; text-align: center; }
/* Tela 2: criação e configuração do relatório */
.builder-form { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.form-grid label { display: grid; gap: 6px; min-width: 0; color: #415a49; font-size: .82rem; font-weight: 650; }
.form-grid label[hidden], .builder-actions button[hidden] { display: none; }
.form-grid input, .form-grid select, .formula-row input, .formula-row select, .aggregation-item select {
  width: 100%; min-width: 0; min-height: 40px; padding: 8px 10px; border: 1px solid #cfdacf; border-radius: 6px; background: #fff; color: #263b2f;
}
.form-grid input:focus, .form-grid select:focus, .formula-row input:focus, .formula-row select:focus, .aggregation-item select:focus { outline: 2px solid #94bf99; outline-offset: 1px; }
.load-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.helper-text { color: #687a6d; font-size: .78rem; }
.customization-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.customization-grid[hidden] { display: none; }
fieldset { min-width: 0; margin: 0; padding: 14px; border: 1px solid #dce7da; border-radius: 8px; }
legend { padding: 0 5px; color: #264a33; font-size: .84rem; font-weight: 750; }
.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: 7px 12px; max-height: 230px; overflow: auto; }
.check-option { display: flex; align-items: flex-start; gap: 8px; min-width: 0; color: #526b58; font-size: .81rem; overflow-wrap: anywhere; }
.check-option input { margin: 2px 0 0; accent-color: #326643; }
.aggregation-list { display: grid; gap: 7px; }
.aggregation-item { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(140px, .8fr); align-items: center; gap: 8px; color: #526b58; font-size: .81rem; }
.aggregation-item select { min-height: 34px; padding: 5px 8px; }
.formula-list { display: grid; gap: 9px; margin-bottom: 10px; }
.formula-row { display: grid; grid-template-columns: minmax(100px, 1fr) minmax(100px, 1fr) 76px minmax(100px, 1fr) auto; gap: 7px; align-items: center; }
.formula-row input, .formula-row select { min-height: 34px; padding: 5px 8px; font-size: .8rem; }
.formula-row .remove-formula { min-width: 34px; padding: 5px; color: #963b36; }
.builder-actions { display: flex; flex-wrap: wrap; gap: 9px; padding-top: 2px; border-top: 1px solid #e5ece4; }
/* Tela 3: prévia dos resultados */
.preview-section { min-width: 0; margin-top: 24px; }
.preview-heading { margin-bottom: 10px; }
.table-wrap { max-height: 62vh; overflow: auto; border: 1px solid #dce5dc; border-radius: 7px; }
table { width: 100%; min-width: 650px; border-collapse: collapse; font-size: .82rem; }
th, td { padding: 9px 10px; border: 1px solid #e0e8df; text-align: left; vertical-align: top; }
thead th { position: sticky; top: 0; z-index: 2; background: #24563a; color: #fff; }
tbody tr:nth-child(even) { background: #f6f9f5; }
tbody tr:hover { background: #edf5ec; }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.empty-cell { padding: 28px; color: #718075; text-align: center; }
tfoot th { position: sticky; bottom: 0; z-index: 2; background: #e7f0e4; color: #193b2c; font-weight: 800; }
tfoot[hidden] { display: none; }

/* Ajustes responsivos */
@media (max-width: 800px) {
  .report-app { width: min(100% - 24px, 1440px); padding-top: 16px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .report-header, .section-heading { align-items: flex-start; }
  .report-header { flex-direction: column; }
  .panel { padding: 14px; }
  .form-grid, .customization-grid { grid-template-columns: minmax(0, 1fr); }
  .formula-row { grid-template-columns: minmax(0, 1fr) 72px minmax(0, 1fr) auto; }
  .formula-row input { grid-column: 1 / -1; }
  .aggregation-item { grid-template-columns: minmax(0, 1fr) 135px; }
}
