*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: #f7f7fb;
  color: #222;
  line-height: 1.4;
}

header {
  background: #3f51b5;
  color: #fff;
  padding: 16px 20px;
}

/* Centraliza o título dentro do logo */
.logo {
  text-align: center;
}
.logo h1 {
  /* Remove huge horizontal margins that break on mobile */
  margin: 0;
  font-size: clamp(18px, 4.5vw, 28px);
}

main {
  max-width: 920px;
  margin: 24px auto;
  padding: 0 16px 48px;
}

section {
  background: #fff;
  border: 1px solid #e6e6ef;
  border-radius: 10px;
  margin-top: 8px;
  /* margin-bottom: 8px; */
  overflow: visible;
}

section > h1,
section > h2 {
  margin: 0;
  padding: 6px 16px;
  background: #f1f3ff;
  border-bottom: 1px solid #e6e6ef;
  cursor: pointer;
  user-select: none;
  position: -webkit-sticky; /* Safari */
  position: sticky;
  top: -1px;
  z-index: 10;
}

section > h1 {
  font-size: 18px;
}

section.open > h1 {
  background-color: #3f51b5;
  color: white;
}

section > h2 {
  font-size: 16px;
}

.group { padding: 0 16px 16px; }
.section-body h3 { color: red; margin: 16px 0; padding: 0 16px; }
#form-funcional > h2 { margin: 16px; }
.q { margin: 12px 0; }
.q > label:first-child { font-weight: 600; display: block; margin-bottom: 8px; }
.label--center { text-align: center; display: block; }

.help { color: #555; font-size: 13px; margin-top: 4px; }
/* Normaliza legenda/ajuda para consistência visual */
#legenda-ivcf {
  padding: 0 16px 12px;
  margin-top: 0;
}

/* Quando a legenda vier logo após o resultado, manter mesmo recuo */
#resultado-ivcf + #legenda-ivcf { padding-top: 0; }

.column, .row { display: flex; gap: 10px; flex-wrap: wrap; }
.column { flex-direction: column; }

.column > label, .row > label {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f7f8ff;
  border: 1px solid #e6e6ef;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.row > label { justify-content: center; min-width: 60px; }

/* Improve tap targets on mobile */
input[type="radio"], input[type="checkbox"] { width: 18px; height: 18px; }
/* Cor azul para controles nativos marcados */
input[type="radio"], input[type="checkbox"] { accent-color: #3f51b5; }

.actions { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid #eee; background: #fafafa; }

button {
  background: #3f51b5;
  border: none;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  transition: background 0.2s ease;
}

button:hover { background: #2f3fa0; }
button.secondary { background: #e0e0f7; color: #1b1b3a; }
button.secondary:hover { background: #c7c7ee; }
button:focus-visible { outline: 3px solid rgba(63,81,181,.35); outline-offset: 2px; }

.resultado { padding: 12px 16px; }
.score { font-size: 15px; margin-top: 6px; }

/* Reduz o restante do conteúdo após nome/data */
.resultado-body { font-size: 90%; }

/* Resumo */
#resumo-tests .item { border-top: 1px dashed #e3e3ef; padding: 10px 0; }
#resumo-tests .item:first-child { border-top: none; }
#resumo-tests .legend { font-size: 12px; color: #555; margin-top: 4px; }

/* Colapsável */
.section-body { display: none !important; }
section.open > .section-body { display: block !important; }
section.collapsible > h1::after,
section.collapsible > h2::after,
section.collapsible > h3::after,
section.collapsible > h4::after {
  content: '▼';
  float: right;
  font-size: 12px;
  color: #555;
}
section.collapsible.open > h1::after,
section.collapsible.open > h2::after,
section.collapsible.open > h3::after,
section.collapsible.open > h4::after { content: '▲'; }

/* Estilo para h3 clicável (como MEDICAMENTOS) */
section.collapsible > h3 {
  cursor: pointer;
  user-select: none;
  margin: 16px 0;
  padding: 0 16px;
  color: red;
}

/* Estilo para h4 clicável em medicamentos */
section.collapsible.medicamento-item {
  margin-bottom: 12px;
  border: 1px solid #e6e6ef;
  border-radius: 8px;
  overflow: hidden;
}

section.collapsible.medicamento-item > h4 {
  margin: 0;
  padding: 10px 12px;
  background: #f9f9fc;
  border-bottom: 1px solid #e6e6ef;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
}

section.collapsible.medicamento-item.open > .section-body {
  padding: 12px;
}

.grid-container { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: flex-end; }
.grid-container-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; align-items: flex-end; }
.grid-container-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; align-items: flex-end; }
.grid-container-6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1rem; align-items: flex-end; }
.form-input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 6px; font: inherit; background: #fff; }
.form-input--date {
  /* max-width: fit-content; */
  text-align: center;
}

/* Centraliza visualmente o input de data dentro da sua coluna */
.q:has(#data_avaliacao) {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Garante que o próprio input não estique e fique centralizado */
#data_avaliacao {
  margin: 0 auto;
}

body.resultado {
  background: #e0e0e0;
}

.page {
  background: white;
  width: 210mm;
  min-height: 297mm;
  margin: 20px auto;
  padding: 20mm;
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

@media (max-width: 720px) {
  header { padding: 12px 14px; }
  .logo { text-align: center; }
  .grid-container, .grid-container-3, .grid-container-5, .grid-container-6 { grid-template-columns: 1fr; }
  .actions {
    flex-wrap: wrap;
    justify-content: center;
    padding: 16px;
  }
  .page { width: 100%; min-height: 0; margin: 0; padding: 16px; box-shadow: none; border-radius: 0; }
  .column > label, .row > label { padding: 10px 12px; }
  .row { gap: 8px; }
  .row > label { min-width: 44px; }
  button { width: 100%; }
  
  /* Prevent iOS text zoom on focus */
  input, textarea, select { font-size: 16px !important; }
  
  /* Ensure images don't overflow */
  img, video { max-width: 100%; height: auto; }
}

/* Improve readability for long headings inside sections on small screens */
section > h2 {
  line-height: 1.3;
}

/* Prevent overflow from very long words/labels */
.q label, section > h2 { word-wrap: break-word; overflow-wrap: anywhere; }

/* Print styles: keep A4 when printing, full width on screen */
@media print {
  body { background: #fff; }
  .page { width: 210mm; min-height: 297mm; margin: 0; padding: 15mm; box-shadow: none; }
  .actions { display: none; }
}

/* Floating PDF button (somente página de resultados) */
#fab-pdf {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #e53935;
  color: #fff;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  cursor: pointer;
  z-index: 1000;
  transition: transform .15s ease, box-shadow .15s ease, background .2s ease;
}
#fab-pdf:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0,0,0,0.25); background: #c62828; }
#fab-pdf:active { transform: translateY(0); }
#fab-pdf svg,
#fab-pdf img {
  pointer-events: none;
  width: 160%;
  height: 160%;
  object-fit: contain;
}
@media print { #fab-pdf { display: none; } }

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.4);
}

.modal-content {
  background-color: #fefefe;
  margin: 15% auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
  max-width: 500px;
  border-radius: 10px;
}

.close-button {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close-button:hover,
.close-button:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}
/* Delete button for medication items */
.delete-medicamento {
  color: red;
  float: right;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  margin-left: 10px;
}

.delete-medicamento:hover {
  color: darkred;
}

/* Estilos para a página de resultado - layout em grid */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  padding: 12px 16px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: #f9f9fc;
  border-radius: 6px;
  border: 1px solid #e6e6ef;
}

.info-label {
  font-weight: 600;
  font-size: 12px;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.info-value {
  font-size: 14px;
  color: #222;
}

.texto-item {
  padding: 12px 16px;
  margin: 8px 0;
  background: #f9f9fc;
  border-left: 3px solid #3f51b5;
  border-radius: 4px;
}

.texto-item strong {
  display: block;
  margin-bottom: 6px;
  color: #3f51b5;
  font-size: 14px;
}

.resultado-body h3 {
  margin: 20px 16px 12px;
  font-size: 16px;
  color: #3f51b5;
  border-bottom: 2px solid #e6e6ef;
  padding-bottom: 6px;
}

.resultado-body section {
  margin-bottom: 16px;
}

.resultado-body .section-body {
  display: block !important;
  padding-bottom: 12px;
}

/* Ajuste responsivo para telas menores */
@media (max-width: 768px) {
  .info-grid {
    grid-template-columns: 1fr;
  }
}

/* Estilos para impressão e PDF */
@media print {
  .info-grid {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .info-item {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .texto-item {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  section {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  h3 {
    break-after: avoid;
    page-break-after: avoid;
  }

  .actions {
    display: none;
  }
}

/* Garantir que os grids sejam renderizados corretamente no PDF */
.resultado-body .info-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
}

.resultado-body .info-item {
  display: flex !important;
  flex-direction: column !important;
}

/* Card para medicamentos */
.medicamento-card {
  background: #ffffff;
  border: 1px solid #e6e6ef;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.medicamento-card h4 {
  margin: 0 0 12px 0;
  color: #3f51b5;
  font-size: 16px;
  font-weight: 600;
  padding-bottom: 8px;
  border-bottom: 1px solid #e6e6ef;
}

.medicamento-card .info-grid {
  margin-top: 12px;
}

.btn-small {
  padding: 6px 12px;
  font-size: 13px;
  background-color: #673ab7; /* Deep Purple */
  color: white;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-small:hover {
  background-color: #512da8;
}
