/* Estilos do painel de análise por IA. */

.ai-panel {
  margin: 28px 0;
  padding: 24px;
  border: 1px solid #d4c9c3;
  border-top: 4px solid #88565e;
  border-radius: 12px;
  background: #fffefb;
  font: 14px/1.6 Arial, sans-serif;
  color: #303530;
  min-width: 0;
}

.ai-panel h2 {
  font-size: 23px;
  margin: 0 0 12px;
}

.ai-panel fieldset {
  border: 0;
  padding: 0;
  min-width: 0;
}

.ai-panel label {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.ai-panel select,
.ai-panel textarea {
  font: inherit;
  border: 1px solid #c8cbbf;
  border-radius: 6px;
  background: white;
  color: inherit;
  padding: 12px;
  width: 100%;
  box-sizing: border-box;
}

.ai-panel textarea {
  line-height: 1.65;
  resize: vertical;
}

.ai-panel .ai-actions,
.ai-panel .ai-selected {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin: 14px 0;
}

.ai-panel .ai-selected button {
  border: 1px solid #c8cbbf;
  border-radius: 18px;
  padding: 8px 12px;
  background: #eff2ea;
  color: #394735;
  font: inherit;
  cursor: pointer;
}

.ai-panel .ai-status {
  color: #88565e;
}

.ai-panel .ai-meta {
  font-size: 12px;
  color: #59605a;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-card-choice {
  margin-top: 14px;
}

.ai-card-choice[aria-pressed="true"] {
  background: #eff2ea;
  border-color: #718361;
}

.ai-panel button:disabled {
  opacity: 0.5;
}

/* Relatório no ecrã: crescimento vertical limitado. */

.ai-panel #ai-answer {
  max-height: 680px;
  overflow: auto;
  padding: 22px;
  border: 1px solid #ddd8cf;
  border-radius: 8px;
  background: white;
  margin: 12px 0 20px;
}

/* Conteúdo comum ao ecrã e ao documento de impressão. */

.ai-report-content {
  font: 14px/1.65 Arial, sans-serif;
  color: #303530;
  white-space: normal;
  overflow-wrap: anywhere;
}

.ai-report-content h2 {
  font-size: 21px;
  line-height: 1.3;
  margin: 26px 0 12px;
  color: #70464e;
}

.ai-report-content h3 {
  font-size: 17px;
  line-height: 1.35;
  margin: 24px 0 10px;
  color: #43533d;
  border-bottom: 1px solid #dce2d5;
  padding-bottom: 7px;
}

.ai-report-content h4 {
  font-size: 15px;
  line-height: 1.4;
  margin: 20px 0 8px;
  color: #303530;
}

.ai-report-content > :first-child {
  margin-top: 0;
}

.ai-report-content p {
  margin: 0 0 12px;
}

.ai-report-content ul,
.ai-report-content ol {
  padding-left: 24px;
  margin: 10px 0 18px;
}

.ai-report-content ul {
  list-style: disc;
}

.ai-report-content ol {
  list-style: decimal;
}

.ai-report-content li {
  padding-left: 3px;
  margin: 0 0 8px;
}

.ai-report-content strong {
  font-weight: 700;
}

.ai-report-content hr {
  border: 0;
  border-top: 1px solid #ddd8cf;
  margin: 24px 0;
}

.ai-report-content pre {
  white-space: pre-wrap;
  padding: 12px;
  background: #f5f3ef;
  border: 1px solid #ddd8cf;
}

.ai-report-content code {
  font-size: 0.92em;
}

/* Tabelas comparativas. */

.ai-table-wrap {
  overflow-x: auto;
  margin: 14px 0 22px;
  border: 1px solid #d5d9ce;
  border-radius: 6px;
}

.ai-report-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
}

.ai-report-content th,
.ai-report-content td {
  padding: 10px 12px;
  border-bottom: 1px solid #dfe2da;
  border-right: 1px solid #dfe2da;
  vertical-align: top;
  min-width: 100px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.ai-report-content th {
  background: #eaf0e3;
  color: #354430;
  font-weight: 700;
}

.ai-report-content td:first-child {
  font-weight: 600;
}

.ai-report-content tr:nth-child(even) td {
  background: #f8f6f2;
}

.ai-report-content tr:last-child td {
  border-bottom: 0;
}

.ai-report-content th:last-child,
.ai-report-content td:last-child {
  border-right: 0;
}

.ai-table-wrap:focus-visible {
  outline: 2px solid #88565e;
  outline-offset: 3px;
}

/* Pré-visualização para impressão ou gravação em PDF. */

body.ai-printing {
  overflow: hidden;
}

#ai-print-root {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: #e9e9e2;
  overflow: auto;
  padding: 24px;
  color: #303530;
  font: 14px/1.65 Arial, sans-serif;
}

.ai-print-document {
  max-width: 210mm;
  min-height: 260mm;
  background: white;
  padding: 16mm;
  margin: auto;
  box-sizing: border-box;
  box-shadow: 0 8px 30px #30353015;
}

.ai-print-document > h1 {
  font: 700 24px/1.3 Arial, sans-serif;
  color: #88565e;
  border-bottom: 3px solid #a8b69a;
  padding-bottom: 18px;
  margin: 24px 0 18px;
}

.ai-print-meta {
  font: 12px/1.6 Arial, sans-serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding-bottom: 18px;
  margin-bottom: 24px;
  border-bottom: 1px solid #ddd8cf;
}

.ai-print-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.ai-print-actions button {
  font: inherit;
  border: 1px solid #d4c9c3;
  border-radius: 6px;
  background: #f7f3ee;
  color: #303530;
  padding: 10px 14px;
  cursor: pointer;
}

.ai-print-actions button:first-child {
  background: #88565e;
  color: white;
  border-color: #88565e;
}

@media (max-width: 600px) {
  .ai-panel {
    padding: 16px;
  }

  .ai-panel #ai-answer {
    padding: 14px;
  }

  #ai-print-root {
    padding: 10px;
  }

  .ai-print-document {
    padding: 20px;
  }
}

/*
 * Impressão:
 * - mostra apenas o relatório;
 * - elimina a limitação de altura;
 * - adapta as tabelas à largura da folha;
 * - repete o cabeçalho quando uma tabela passa de página.
 */

@media print {
  body.ai-printing {
    overflow: visible !important;
  }

  body.ai-printing > :not(#ai-print-root) {
    display: none !important;
  }

  body.ai-printing > #ai-print-root {
    display: block !important;
    position: static !important;
    padding: 0 !important;
    background: white;
    overflow: visible !important;
  }

  #ai-print-root .ai-print-document {
    width: 100%;
    max-width: none;
    min-height: 0;
    padding: 0;
    margin: 0;
    background: white;
    box-shadow: none;
  }

  #ai-print-root .ai-print-actions {
    display: none !important;
  }

  #ai-print-root .ai-report-content {
    font-size: 10pt;
    line-height: 1.5;
    max-height: none;
    overflow: visible;
  }

  #ai-print-root .ai-report-content h2 {
    font-size: 16pt;
  }

  #ai-print-root .ai-report-content h3 {
    font-size: 12pt;
  }

  #ai-print-root .ai-report-content h4 {
    font-size: 10.5pt;
  }

  #ai-print-root .ai-report-content h2,
  #ai-print-root .ai-report-content h3,
  #ai-print-root .ai-report-content h4 {
    break-after: avoid;
  }

  #ai-print-root p,
  #ai-print-root li {
    orphans: 3;
    widows: 3;
  }

  #ai-print-root .ai-table-wrap {
    overflow: visible;
    border-radius: 0;
  }

  #ai-print-root table {
    table-layout: fixed;
    font-size: 9pt;
    width: 100%;
  }

  #ai-print-root th,
  #ai-print-root td {
    min-width: 0;
    padding: 7px;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  #ai-print-root thead {
    display: table-header-group;
  }

  #ai-print-root tr {
    break-inside: avoid;
  }

  #ai-print-root .ai-print-meta {
    font-size: 9pt;
  }
}
