
/* Lançamento de Resultados — complementos ao styles.css do projeto */
.analysis-page,
.micro-page,
.lab-page {
  min-height: 0;
}

.analysis-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(190px, 1fr));
  gap: 16px;
}

.analysis-choice {
  min-height: 145px;
  padding: 22px;
  border: 1px solid #d7e6f7;
  border-radius: 18px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.analysis-choice:hover {
  transform: translateY(-2px);
  border-color: #7cbcff;
  box-shadow: 0 12px 28px rgba(21, 113, 211, .14);
}

.analysis-choice:disabled {
  cursor: not-allowed;
  opacity: .55;
  transform: none;
  box-shadow: none;
}

.analysis-choice .analysis-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  margin-bottom: 14px;
  background: #e9f4ff;
  color: #0665c8;
  font-size: 1.35rem;
}

.analysis-choice strong {
  display: block;
  color: #092f62;
  font-size: 1rem;
}

.analysis-choice small {
  display: block;
  margin-top: 7px;
  color: #7085a1;
  line-height: 1.4;
}

.analysis-modal-card {
  width: min(940px, calc(100vw - 30px));
}

.micro-table {
  min-width: 1220px;
}

.micro-list-toolbar {
  grid-template-columns: minmax(280px, 1fr) 160px 170px 170px 170px auto;
}

.col-reg { width: 8%; }
.col-farm-micro { width: 24%; }
.col-origin { width: 10%; }
.col-collection { width: 11%; }
.col-inoc { width: 11%; }
.col-result { width: 11%; }
.col-progress { width: 11%; }
.col-state { width: 8%; }
.col-actions-micro { width: 6%; }

.farm-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.farm-code-avatar {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  border: 1px solid #c8e1ff;
  background: #eaf4ff;
  color: #0560c5;
  font-size: .77rem;
  font-weight: 900;
}

.farm-identity strong,
.farm-identity small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.farm-identity strong { color: #0a2f61; }
.farm-identity small { margin-top: 4px; color: #7286a0; }

.progress-cell {
  min-width: 110px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  color: #375778;
  font-size: .78rem;
  font-weight: 700;
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6eef7;
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0b69d1, #2a9cf1);
}

.test-layout {
  height: 100vh;
  overflow: hidden;
}

.test-content {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  height: calc(100vh - 76px);
  overflow: hidden;
  padding: 18px 24px 20px;
}

.test-header-card,
.animal-entry-card,
.test-table-card,
.lab-toolbar-card {
  border: 1px solid #d9e6f4;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 8px 26px rgba(30, 91, 153, .07);
}

.test-header-card {
  padding: 17px 19px;
}

.test-header-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1.5fr) repeat(5, minmax(125px, .65fr));
  gap: 14px;
  align-items: end;
}

.header-farm {
  display: flex;
  gap: 13px;
  align-items: center;
  min-width: 0;
}

.header-farm h1 {
  margin: 0;
  color: #092f61;
  font-size: 1.12rem;
}

.header-farm p {
  margin: 5px 0 0;
  color: #71859e;
  font-size: .85rem;
}

.metric-box {
  min-height: 65px;
  padding: 10px 12px;
  border-radius: 13px;
  background: #f4f9ff;
  border: 1px solid #dfecf9;
}

.metric-box label,
.header-date label {
  display: block;
  margin-bottom: 6px;
  color: #5c718c;
  font-size: .73rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-box strong {
  color: #0a386e;
  font-size: 1rem;
}

.header-date input {
  width: 100%;
}

.animal-entry-card {
  padding: 15px 18px;
}

.animal-entry-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 13px;
}

.animal-entry-top h2 {
  margin: 0;
  color: #0a2e5c;
  font-size: 1rem;
}

.capacity-indicator {
  color: #607692;
  font-size: .82rem;
}

.capacity-indicator strong {
  color: #0871d9;
}

.animal-entry-grid {
  display: grid;
  grid-template-columns: 75px minmax(110px, .75fr) minmax(125px, 1fr) minmax(160px, 1fr) minmax(220px, 1.35fr) auto;
  gap: 11px;
  align-items: end;
}

.animal-flags {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  padding-top: 3px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #26496f;
  font-size: .85rem;
  font-weight: 700;
}

.discard-reason-wrap {
  min-width: 260px;
  flex: 1;
  max-width: 480px;
}

.test-table-card {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.test-table {
  min-width: 1180px;
}

.col-num { width: 6%; }
.col-animal-number { width: 11%; }
.col-animal-name { width: 12%; }
.col-teat { width: 11%; }
.col-event { width: 18%; }
.col-discard { width: 14%; }
.col-summary { width: 20%; }
.col-actions-test { width: 8%; }

.result-summary strong,
.result-summary small {
  display: block;
}

.result-summary strong {
  color: #0b376a;
}

.result-summary small {
  margin-top: 4px;
  color: #71859d;
}

.capacity-warning {
  color: #ad6500;
  font-weight: 700;
}

.result-modal-card {
  width: min(1080px, calc(100vw - 26px));
  max-height: calc(100vh - 18px);
}

.result-form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 13px;
}

.result-form-grid .span-2 { grid-column: span 2; }
.result-form-grid .span-all { grid-column: 1 / -1; }

.result-section-title {
  grid-column: 1 / -1;
  margin: 7px 0 0;
  padding-bottom: 8px;
  border-bottom: 1px solid #e4edf6;
  color: #0b386d;
  font-size: .95rem;
}

.dual-results {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.result-column {
  padding: 15px;
  border: 1px solid #dfebf7;
  border-radius: 15px;
  background: #f9fcff;
}

.result-column h3 {
  margin: 0 0 13px;
  color: #0a3568;
  font-size: .95rem;
}

.result-column-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
}

.second-result-hidden {
  display: none;
}

.lab-page-grid {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  height: 100%;
}

.lab-categories {
  padding: 12px;
  border: 1px solid #dae7f5;
  border-radius: 17px;
  background: #fff;
  overflow: auto;
}

.lab-category-btn {
  width: 100%;
  margin-bottom: 6px;
  padding: 11px 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #315577;
  text-align: left;
  font-weight: 750;
  cursor: pointer;
}

.lab-category-btn.active {
  background: #e7f3ff;
  color: #075fbe;
}

.lab-main {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.lab-toolbar-card {
  padding: 13px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
}

.lab-option-list {
  min-height: 0;
  overflow: auto;
  border: 1px solid #dbe7f4;
  border-radius: 17px;
  background: #fff;
}

.lab-option-row {
  display: grid;
  grid-template-columns: 100px minmax(180px, 1fr) 100px 110px;
  align-items: center;
  gap: 14px;
  min-height: 62px;
  padding: 10px 16px;
  border-bottom: 1px solid #e7eef6;
}

.lab-option-row:last-child { border-bottom: 0; }

.option-code {
  font-weight: 900;
  color: #075fbe;
}

.option-active {
  color: #087d4c;
  font-weight: 800;
}

@media (max-width: 1250px) {
  .test-header-grid {
    grid-template-columns: minmax(230px, 1.4fr) repeat(5, minmax(110px, .65fr));
    gap: 9px;
  }

  .animal-entry-grid {
    grid-template-columns: 65px 110px 120px 145px minmax(190px, 1fr) auto;
  }
}

@media (max-width: 1050px) {
  .analysis-choice-grid { grid-template-columns: repeat(2, 1fr); }
  .micro-list-toolbar { grid-template-columns: 1fr 1fr 1fr; }
  .micro-list-toolbar .search-box { grid-column: 1 / -1; }
}


/* Ajustes v2 solicitados */
.test-header-grid {
  grid-template-columns: minmax(310px, 1.65fr) repeat(4, minmax(155px, .8fr));
  align-items: stretch;
}
.header-farm,
.metric-box,
.header-date {
  min-height: 76px;
}
.header-farm {
  padding: 8px 4px;
}
.metric-box,
.header-date {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.header-date .control,
.header-date input {
  height: 48px;
}
.animal-entry-grid {
  grid-template-columns: 68px minmax(115px,.8fr) minmax(125px,1fr) minmax(190px,1.05fr) minmax(240px,1.55fr) auto;
  align-items: end;
}
.teat-field { min-width: 190px; }
.event-field-wrap {
  display: grid;
  grid-template-rows: 24px auto;
  gap: 2px;
}
.no-info-above {
  align-self: end;
  justify-self: start;
  font-size: .78rem;
}
.animal-flags {
  grid-column: 1 / -1;
  min-height: 46px;
  align-items: end;
}
.discard-reason-wrap[hidden] { display: none !important; }
.full-micro-table {
  min-width: 1900px;
  table-layout: fixed;
}
.col-num { width: 58px; }
.col-animal-combined { width: 170px; }
.col-teat-small { width: 95px; }
.col-event-full { width: 170px; }
.col-lab { width: 95px; }
.col-result-full { width: 170px; }
.col-onfarm { width: 105px; }
.col-actions-test { width: 76px; }
.full-micro-table th,
.full-micro-table td {
  vertical-align: middle;
  white-space: normal;
}
.full-micro-table td {
  min-height: 68px;
}
.full-micro-table td strong {
  color: #0b315e;
}
.discard-small {
  display: block;
  margin-top: 5px;
  color: #b24c42;
  font-size: .72rem;
}


/* Teto com seleção múltipla */
.teat-multiselect {
  position: relative;
  width: 100%;
}

.teat-multiselect-trigger {
  width: 100%;
  min-height: 48px;
  padding: 7px 11px;
  border: 1px solid #c9dbef;
  border-radius: 12px;
  background: #fff;
  color: #173d68;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  cursor: pointer;
}

.teat-multiselect.open .teat-multiselect-trigger {
  border-color: #1684e8;
  box-shadow: 0 0 0 3px rgba(22,132,232,.12);
}

.teat-selected-values {
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.teat-placeholder {
  color: #7b8da4;
  font-size: .86rem;
}

.teat-arrow {
  flex: 0 0 auto;
  color: #1d4b79;
  font-size: 1rem;
}

.teat-chip {
  max-width: 100%;
  min-height: 28px;
  padding: 4px 5px 4px 9px;
  border-radius: 9px;
  background: #e5f3ff;
  color: #075fbf;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .82rem;
  font-weight: 800;
}

.teat-chip-remove {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #315a82;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1rem;
}

.teat-chip-remove:hover {
  background: rgba(7,95,191,.12);
}

.teat-options {
  position: absolute;
  z-index: 180;
  top: calc(100% + 5px);
  left: 0;
  width: max(100%, 210px);
  max-height: 260px;
  overflow-y: auto;
  padding: 5px;
  border: 1px solid #bcd8f4;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(18,65,111,.22);
}

.teat-options[hidden] {
  display: none !important;
}

.teat-option {
  width: 100%;
  min-height: 41px;
  padding: 9px 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #173b63;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  cursor: pointer;
}

.teat-option:hover,
.teat-option.selected {
  background: #e5f3ff;
  color: #075fbf;
}

.teat-option:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.teat-option-check {
  min-width: 16px;
  font-weight: 900;
}

.result-form-grid .teat-multiselect {
  width: 100%;
}


/* Evento com seleção múltipla */
.event-multiselect {
  position: relative;
  width: 100%;
}

.event-multiselect-trigger {
  width: 100%;
  min-height: 48px;
  padding: 7px 11px;
  border: 1px solid #c9dbef;
  border-radius: 12px;
  background: #fff;
  color: #173d68;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  cursor: pointer;
}

.event-multiselect.open .event-multiselect-trigger {
  border-color: #1684e8;
  box-shadow: 0 0 0 3px rgba(22,132,232,.12);
}

.event-selected-values {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
}

.event-placeholder {
  color: #7b8da4;
  font-size: .86rem;
}

.event-chip {
  min-height: 28px;
  padding: 4px 5px 4px 9px;
  border-radius: 9px;
  background: #e5f3ff;
  color: #075fbf;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .82rem;
  font-weight: 800;
}

.event-chip-remove {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.event-options {
  position: absolute;
  z-index: 180;
  top: calc(100% + 5px);
  left: 0;
  width: max(100%, 300px);
  max-height: 280px;
  overflow-y: auto;
  padding: 5px;
  border: 1px solid #bcd8f4;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(18,65,111,.22);
}

.event-options[hidden] { display: none !important; }

.event-option {
  width: 100%;
  min-height: 41px;
  padding: 9px 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #173b63;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  cursor: pointer;
}

.event-option:hover,
.event-option.selected {
  background: #e5f3ff;
  color: #075fbf;
}

.event-option:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.entry-flags-top {
  min-height: 24px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 5px;
}

.discard-expanded {
  grid-column: 1 / -1;
  padding: 12px 14px;
  border: 1px solid #f1d6d2;
  border-radius: 13px;
  background: #fff8f7;
}

.discard-expanded[hidden] {
  display: none !important;
}

.event-special-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  background: #f3f9ff;
  border: 1px solid #d9eafa;
}

.event-special-results[hidden] {
  display: none !important;
}

.animal-entry-card {
  transition: min-height .18s ease;
}


/* Resultados condicionais do Evento em uma linha abaixo */
.event-special-results-below {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 2px;
  padding: 13px 14px;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  align-items: end;
}

.event-special-results-below .field {
  margin: 0;
}

.event-special-results-below .control {
  min-height: 46px;
}

@media (max-width: 1050px) {
  .event-special-results-below {
    grid-template-columns: 1fr;
  }
}


/* Modal de resultados em largura quase total */
.result-modal-card {
  width: calc(100vw - 28px);
  max-width: none;
  height: calc(100vh - 24px);
  max-height: calc(100vh - 24px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.result-modal-card > form {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.result-modal-card .modal-body {
  min-height: 0;
  overflow: auto;
  padding: 18px 20px;
}

.result-form-grid {
  grid-template-columns: 80px minmax(140px, .8fr) minmax(160px, .9fr) minmax(300px, 1.6fr);
  gap: 12px;
  align-items: start;
}

.result-form-grid > .field {
  min-width: 0;
}

.result-form-grid .span-2 {
  grid-column: span 1;
}

.result-form-grid .span-all,
.result-section-title,
.micro-results-matrix,
.second-result-hint,
.dual-results {
  grid-column: 1 / -1;
}

/* Padronização da altura de todos os controles */
.result-modal-card .control,
.result-modal-card .teat-multiselect-trigger,
.result-modal-card .event-multiselect-trigger {
  width: 100%;
  height: 48px;
  min-height: 48px;
  box-sizing: border-box;
}

.result-modal-card textarea.control {
  height: auto;
  min-height: 78px;
}

.result-modal-card .field > label {
  min-height: 19px;
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

/* Grade horizontal semelhante ao modelo já utilizado no Power Apps */
.micro-results-matrix {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 9px 12px;
  padding: 14px;
  border: 1px solid #d7e8f8;
  border-radius: 14px;
  background: #eaf6ff;
}

.result-row-label {
  min-height: 70px;
  display: flex;
  align-items: center;
  color: #0a376b;
  font-size: .85rem;
  font-weight: 900;
}

.result-row-controls {
  display: grid;
  grid-template-columns:
    minmax(100px, .8fr)
    minmax(100px, .72fr)
    minmax(110px, .82fr)
    minmax(100px, .72fr)
    minmax(100px, .72fr)
    minmax(105px, .78fr)
    minmax(95px, .68fr)
    minmax(100px, .72fr)
    minmax(100px, .72fr)
    minmax(180px, 1.35fr);
  gap: 7px;
  align-items: end;
  min-width: 1120px;
}

.matrix-result-field {
  min-width: 0;
  margin: 0;
}

.matrix-result-field > label {
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  font-size: .72rem;
}

.matrix-result-field .control {
  padding-left: 9px;
  padding-right: 9px;
}

.second-result-detail[hidden] {
  display: none !important;
}

.second-result-hint {
  margin: -3px 0 2px 108px;
  color: #6b8099;
  font-size: .78rem;
}

.second-result-hint[hidden] {
  display: none !important;
}

/* Resultado condicionado ao evento: linha limpa, sem card azul estreito */
.event-special-results-below {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 360px));
  gap: 14px;
  width: 100%;
  margin-top: 13px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.event-special-results-below[hidden] {
  display: none !important;
}

.event-special-results-below .field {
  margin: 0;
}

@media (max-width: 1250px) {
  .result-modal-card {
    width: calc(100vw - 14px);
    height: calc(100vh - 14px);
    max-height: calc(100vh - 14px);
  }

  .result-form-grid {
    grid-template-columns: 72px minmax(125px, .8fr) minmax(145px, .9fr) minmax(260px, 1.5fr);
  }
}


/* Identificação em uma única linha */
.identification-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns:
    62px
    minmax(86px, .38fr)
    minmax(120px, .55fr)
    minmax(190px, .82fr)
    minmax(260px, 1.25fr)
    minmax(170px, .78fr)
    minmax(170px, .78fr);
  gap: 9px;
  align-items: end;
  width: 100%;
}

.identification-row > .field,
.identification-event-results > .field {
  min-width: 0;
  margin: 0;
}

.identification-row .field-help {
  display: none;
}

.identification-event-results {
  display: contents;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.identification-event-results[hidden] {
  display: none !important;
}

.identification-event-results .field {
  min-width: 0;
}

.identification-event-results .field label {
  font-size: .72rem;
  line-height: 1.15;
}

.identification-row .control,
.identification-row .teat-multiselect-trigger,
.identification-row .event-multiselect-trigger,
.identification-event-results .control {
  height: 48px;
  min-height: 48px;
}

/* Resultado agora inclui On Farm em cada linha */
.result-row-controls {
  grid-template-columns:
    minmax(92px, .72fr)
    minmax(92px, .65fr)
    minmax(102px, .75fr)
    minmax(92px, .65fr)
    minmax(92px, .65fr)
    minmax(98px, .72fr)
    minmax(90px, .62fr)
    minmax(94px, .66fr)
    minmax(94px, .66fr)
    minmax(165px, 1.2fr)
    minmax(105px, .75fr);
  min-width: 1240px;
}

/* Campo de observação ocupa toda a largura */
#resultNotes {
  width: 100%;
}

@media (max-width: 1350px) {
  .identification-row {
    grid-template-columns:
      58px
      90px
      125px
      180px
      minmax(230px, 1fr)
      155px
      155px;
  }
}


/* Ícone de informação dos campos com histórico */
.label-with-info {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 5px;
  position: relative;
}

.field-info-button {
  width: 17px;
  height: 17px;
  min-width: 17px;
  padding: 0;
  border: 1px solid #84a8cb;
  border-radius: 50%;
  background: #fff;
  color: #26618f;
  display: inline-grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: 11px;
  font-weight: 700;
  font-style: italic;
  line-height: 1;
  cursor: pointer;
}

.field-info-button:hover {
  border-color: #0875d1;
  background: #e7f3ff;
  color: #075fb7;
}

/* Pequeno modal de histórico, com uma única coluna */
.history-modal-backdrop {
  z-index: 600;
  align-items: center;
  justify-content: center;
}

.history-modal-card {
  width: min(320px, calc(100vw - 32px));
  max-height: min(520px, calc(100vh - 40px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid #bcd5ea;
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 18px 52px rgba(11, 55, 96, .28);
}

.history-modal-header {
  min-height: 70px;
  padding: 14px 15px;
  border-bottom: 1px solid #dce8f3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.history-modal-header h2 {
  margin: 0;
  color: #092f60;
  font-size: 1rem;
}

.history-modal-header p {
  margin: 5px 0 0;
  color: #71859d;
  font-size: .75rem;
  line-height: 1.35;
}

.history-modal-body {
  min-height: 120px;
  overflow: auto;
  padding: 8px 12px 12px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.history-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 11px;
  background: #eaf5ff;
  color: #0a416f;
  border-bottom: 1px solid #cfe0ee;
  text-align: left;
  font-size: .76rem;
  text-transform: uppercase;
}

.history-table td {
  padding: 10px 11px;
  border-bottom: 1px solid #e2eaf1;
  color: #263f58;
  font-size: .88rem;
}

.history-table tbody tr:hover td {
  background: #f2f8fe;
}

.history-empty,
.history-loading {
  padding: 26px 12px;
  color: #6e8298;
  text-align: center;
  font-size: .84rem;
}


/* =========================================================
   DROPDOWNS PADRONIZADOS — CULTURA MICROBIOLÓGICA
   Mesmo padrão visual do lookup Fazenda / Produtor
   ========================================================= */

.animal-entry-card,
.animal-entry-card form,
.animal-entry-grid,
.result-modal-card,
.result-modal-card form,
.result-modal-card .modal-body,
.result-form-grid,
.identification-row,
.micro-results-matrix,
.result-row-controls {
  position: relative;
}

.animal-entry-card,
.animal-entry-card form,
.animal-entry-grid,
.result-form-grid,
.identification-row,
.micro-results-matrix,
.result-row-controls {
  overflow: visible;
}

.field:has(.micro-lookup.open),
.field:has(.teat-multiselect.open),
.field:has(.event-multiselect.open),
.matrix-result-field:has(.micro-lookup.open) {
  z-index: 1000;
}

.micro-lookup {
  position: relative;
  width: 100%;
  min-width: 0;
  z-index: 1;
}

.micro-lookup.open {
  z-index: 1001;
}

.micro-lookup-input {
  width: 100%;
  height: 48px;
  min-height: 48px;
  padding: 0 76px 0 14px !important;
  border: 1px solid #c9dbef;
  border-radius: 13px;
  background: #fff;
  color: #173d68;
  font-family: inherit;
  font-size: .88rem;
  font-weight: 500;
  outline: none;
  box-sizing: border-box;
  transition: border-color .18s ease, box-shadow .18s ease, border-radius .18s ease;
}

.micro-lookup-input::placeholder {
  color: #7b8da4;
  font-weight: 400;
}

.micro-lookup-input:focus,
.micro-lookup.open .micro-lookup-input {
  border-color: #2694ed;
  box-shadow: 0 0 0 4px rgba(38,148,237,.11), 0 8px 20px rgba(22,103,177,.06);
}

.micro-lookup-clear,
.micro-lookup-toggle {
  position: absolute;
  top: 24px;
  z-index: 5;
  padding: 0;
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  transform: translateY(-50%);
}

.micro-lookup-clear {
  right: 41px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: #7b8fa5;
  display: none;
  font: 20px/1 Arial,sans-serif;
}

.micro-lookup.has-value .micro-lookup-clear { display: grid; }
.micro-lookup-clear:hover { background: #eaf5ff; color: #0872ca; }

.micro-lookup-toggle {
  right: 5px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  color: #173f6a;
  font-size: 10px;
  transition: background .16s ease, transform .18s ease;
}

.micro-lookup-toggle:hover { background: #edf6ff; }
.micro-lookup.open .micro-lookup-toggle { transform: translateY(-50%) rotate(180deg); }

.micro-lookup-results,
.teat-options,
.event-options {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  z-index: 1002 !important;
  width: 100% !important;
  min-width: 100% !important;
  max-width: 100% !important;
  max-height: 245px;
  padding: 7px !important;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid rgba(53,151,231,.24) !important;
  border-radius: 12px 12px 16px 16px !important;
  background: rgba(255,255,255,.985) !important;
  box-shadow: 0 14px 30px rgba(17,61,105,.14), 0 0 0 3px rgba(43,149,232,.04) !important;
  backdrop-filter: blur(12px);
}

.micro-lookup-results[hidden],
.teat-options[hidden],
.event-options[hidden] { display: none !important; }

.micro-lookup-item,
.teat-option,
.event-option {
  width: 100%;
  min-height: 45px;
  padding: 10px 12px !important;
  border: 0 !important;
  border-radius: 10px !important;
  background: transparent !important;
  color: #14375f !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}

.micro-lookup-item:hover,
.micro-lookup-item.active,
.micro-lookup-item.selected,
.teat-option:hover,
.teat-option.selected,
.event-option:hover,
.event-option.selected {
  background: linear-gradient(90deg,#edf7ff,#f7fbff) !important;
  color: #086abb !important;
  transform: translateX(2px);
}

.micro-lookup-item-content { min-width: 0; flex: 1; }
.micro-lookup-item-title,
.micro-lookup-item-subtitle { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.micro-lookup-item-title { font-size: 14px; font-weight: 700; }
.micro-lookup-item-subtitle { margin-top: 3px; color: #7a8ca0; font-size: 12px; font-weight: 400; }
.micro-lookup-check,
.teat-option-check,
.event-option-check { min-width: 18px; color: #0871d9; font-weight: 900; text-align: center; }
.micro-lookup-empty { min-height: 65px; padding: 16px; color: #7b8ca0; display: grid; place-items: center; text-align: center; font-size: 13px; }

.teat-multiselect-trigger,
.event-multiselect-trigger {
  min-height: 48px;
  padding: 7px 42px 7px 11px !important;
  border: 1px solid #c9dbef !important;
  border-radius: 13px !important;
  background: #fff !important;
  box-shadow: none;
  position: relative;
}

.teat-multiselect.open .teat-multiselect-trigger,
.event-multiselect.open .event-multiselect-trigger {
  border-color: #2694ed !important;
  box-shadow: 0 0 0 4px rgba(38,148,237,.11), 0 8px 20px rgba(22,103,177,.06) !important;
}

.teat-arrow,
.event-arrow {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: #173f6a;
  font-size: 13px;
}

.teat-multiselect.open .teat-arrow,
.event-multiselect.open .event-arrow { transform: translateY(-50%) rotate(180deg); }

.teat-chip,
.event-chip {
  min-height: 28px;
  padding: 4px 5px 4px 9px;
  border-radius: 9px;
  background: #e5f3ff;
  color: #075fbf;
  font-size: .78rem;
  font-weight: 800;
}

.result-row-controls .micro-lookup-input { font-size: .78rem; padding-left: 9px !important; }
.result-row-controls .micro-lookup-clear { right: 36px; }
.result-row-controls .micro-lookup-toggle { width: 34px; }
.result-row-controls .micro-lookup-results { min-width: 190px !important; width: max(100%,190px) !important; }

.event-special-results .micro-lookup-results,
.identification-event-results .micro-lookup-results { min-width: 260px !important; width: 100% !important; }


/* =========================================================
   AJUSTES FINAIS — DATAS, Nº ANIMAL E SETAS DOS MULTISELECTS
   ========================================================= */

/*
  As setas de Teto e Evento passam a usar o mesmo acabamento
  visual dos botões dos demais dropdowns.
*/
.teat-arrow,
.event-arrow {
  position: absolute !important;
  top: 50% !important;
  right: 5px !important;

  width: 38px !important;
  height: 38px !important;

  border-radius: 10px;
  background: #edf6ff;

  display: grid !important;
  place-items: center;

  color: #173f6a !important;
  font-size: 10px !important;
  line-height: 1;

  pointer-events: none;
  transform: translateY(-50%) !important;

  transition:
    background .16s ease,
    color .16s ease,
    transform .18s ease;
}

.teat-multiselect-trigger:hover .teat-arrow,
.event-multiselect-trigger:hover .event-arrow {
  background: #e2f1ff;
  color: #086abb !important;
}

.teat-multiselect.open .teat-arrow,
.event-multiselect.open .event-arrow {
  background: #dceeff;
  color: #075fbf !important;
  transform: translateY(-50%) rotate(180deg) !important;
}

/* Reserva corretamente a área do botão cheio à direita. */
.teat-multiselect-trigger,
.event-multiselect-trigger {
  padding-right: 49px !important;
}

/*
  Mantém os chips bem preenchidos e alinhados com o visual
  dos dropdowns simples.
*/
.teat-chip,
.event-chip {
  min-height: 30px !important;
  padding: 5px 6px 5px 10px !important;
  border: 1px solid #d4eaff;
  border-radius: 10px !important;
  background: linear-gradient(145deg, #e3f2ff, #edf7ff) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.85);
}

/* Nº Animal permanece texto, mas recebe comportamento numérico. */
#animalNumber,
#editAnimalNumber {
  font-variant-numeric: tabular-nums;
}


/* =========================================================
   CORREÇÃO DEFINITIVA — ÍCONES DO SELETOR DE ANÁLISES
   ========================================================= */

.analysis-choice {
  position: relative;
  overflow: hidden !important;
}

.analysis-choice .analysis-icon {
  width: 58px !important;
  height: 58px !important;
  min-width: 58px !important;
  min-height: 58px !important;

  margin-bottom: 14px !important;
  padding: 0 !important;

  display: flex !important;
  align-items: center !important;
  justify-content: center !important;

  border: 1px solid #d8e9fb;
  border-radius: 16px !important;

  background: #eef7ff;
  overflow: hidden !important;
}

.analysis-choice .analysis-icon img {
  display: block !important;

  width: 44px !important;
  height: 44px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: 44px !important;
  max-height: 44px !important;

  object-fit: contain !important;
  object-position: center !important;

  user-select: none;
  pointer-events: none;
}

.analysis-choice:disabled {
  opacity: 1 !important;
}

.analysis-choice:disabled .analysis-icon,
.analysis-choice:disabled strong,
.analysis-choice:disabled small {
  opacity: .52;
}

/* =========================================================
   AÇÕES DA TABELA MICROBIOLÓGICA
   ========================================================= */

.test-table .action-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.test-table .delete-action {
  background: #fff0f0;
  color: #c72b2b;
}

.test-table .delete-action:hover {
  background: #ffe3e3;
  color: #a81717;
}

/*
  Garante que o modal de confirmação fique acima do modal
  de resultado e das listas abertas.
*/
#deleteAnimalModal {
  z-index: 1600;
}


/* =========================================================
   INDICADORES E REGRAS DE RESULTADO
   ========================================================= */
.capacity-indicators{display:flex;align-items:center;justify-content:flex-end;gap:18px;flex-wrap:wrap}.capacity-finished strong{color:#087448}.capacity-warning.finished{color:#087448}.micro-lookup-item.rule-disabled{opacity:.62;cursor:not-allowed;background:#f7f9fc}.micro-lookup-item.rule-disabled:hover{transform:none;background:#f7f9fc;color:#14375f}.micro-lookup-rule-reason{display:block;margin-top:4px;color:#c43c3c;font-size:11px;font-weight:600;white-space:normal;line-height:1.3}.result-rule-message{display:block;margin-top:5px;color:#c72b2b;font-size:11px;font-weight:650;line-height:1.3}.matrix-result-field.rule-required .control,.rule-required-input{border-color:#df4545!important;box-shadow:0 0 0 3px rgba(223,69,69,.12)!important;background:#fffafa!important}.matrix-result-field.rule-required>label{color:#b92828}.event-option-check{white-space:nowrap}


/* =========================================================
   LAYOUT FINAL — EVENTOS LONGOS E UFC OBRIGATÓRIO
   ========================================================= */

/* Dois eventos longos permanecem em uma única linha. */
.event-selected-values {
  min-width: 0;
  flex: 1;
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  gap: 6px;
  overflow: hidden;
}

.event-selected-values .event-placeholder {
  grid-column: 1 / -1;
}

.event-selected-values .event-chip:only-child {
  grid-column: 1 / -1;
  width: fit-content;
  max-width: 100%;
}

.event-chip {
  min-width: 0 !important;
  max-width: 100% !important;
  width: 100%;
  display: flex !important;
  align-items: center;
  overflow: hidden;
}

.event-chip-text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-chip-remove {
  flex: 0 0 auto;
}

.event-multiselect-trigger {
  height: 48px !important;
  min-height: 48px !important;
  overflow: hidden;
}

/* Título do UFC com alerta compacto, sem texto abaixo do campo. */
.ufc-field-label {
  position: relative;
  min-height: 20px;
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.ufc-alert-icon {
  position: relative;
  width: 18px;
  height: 18px;
  border: 1px solid #ef4444;
  border-radius: 50%;
  background: #fff1f1;
  color: #d62828;
  display: inline-grid;
  place-items: center;
  font: 800 12px/1 Arial, sans-serif;
  cursor: help;
  animation: ufc-alert-pulse 1.8s ease-in-out infinite;
}

.ufc-alert-icon[hidden] {
  display: none !important;
}

.ufc-alert-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  z-index: 1700;
  width: max-content;
  max-width: 270px;
  padding: 9px 11px;
  border: 1px solid #f3b8b8;
  border-radius: 10px;
  background: #fff;
  color: #9f1d1d;
  box-shadow: 0 10px 25px rgba(83,25,25,.16), 0 0 0 3px rgba(239,68,68,.05);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%,5px);
  transition: opacity .16s ease, visibility .16s ease, transform .16s ease;
}

.ufc-alert-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 5px);
  z-index: 1701;
  width: 8px;
  height: 8px;
  border-right: 1px solid #f3b8b8;
  border-bottom: 1px solid #f3b8b8;
  background: #fff;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) rotate(45deg);
  transition: opacity .16s ease, visibility .16s ease;
}

.ufc-alert-icon:hover::after,
.ufc-alert-icon:focus::after,
.ufc-alert-icon:hover::before,
.ufc-alert-icon:focus::before {
  opacity: 1;
  visibility: visible;
}

.ufc-alert-icon:hover::after,
.ufc-alert-icon:focus::after {
  transform: translate(-50%,0);
}

.matrix-result-field.rule-required .control,
.control.rule-required-input {
  border-color: #ef4444 !important;
  background: #fffafa !important;
  box-shadow: 0 0 0 3px rgba(239,68,68,.10) !important;
}

.matrix-result-field.rule-required > label {
  color: #d62828;
}

.micro-lookup.lookup-rule-disabled {
  opacity: .68;
}

.micro-lookup.lookup-rule-disabled .micro-lookup-input {
  background: #f6f8fb !important;
  cursor: not-allowed;
}

.micro-lookup.lookup-rule-disabled .micro-lookup-toggle {
  cursor: not-allowed;
}

/* Regra antiga não ocupa mais espaço. */
.result-rule-message {
  display: none !important;
}

@keyframes ufc-alert-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.18); }
  50% { box-shadow: 0 0 0 5px rgba(239,68,68,0); }
}

/* =========================================================
   LISTA DE RESULTADOS — ALTURA E ROLAGEM CORRIGIDAS
   ========================================================= */

/*
  Esta página possui um contêiner intermediário:
  #microbiologyList.

  Ele precisa participar do layout flexível; caso contrário,
  a tabela cresce além da tela e o rodapé fica oculto.
*/

body[data-page="results"] {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body[data-page="results"] .app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

body[data-page="results"] .main.users-main {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

body[data-page="results"] .content.users-content.analysis-page {
  height: calc(100vh - 76px);
  height: calc(100dvh - 76px);
  min-height: 0;

  display: flex;
  flex-direction: column;

  overflow: hidden;
}

/* Título da página permanece no topo. */
body[data-page="results"] .analysis-page > .page-heading {
  flex: 0 0 auto;
}

/*
  Este era o elemento ausente no encadeamento flexível.
  Ele recebe todo o espaço restante abaixo do título.
*/
body[data-page="results"] #microbiologyList {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;

  display: flex;
  flex-direction: column;
  gap: 14px;

  overflow: hidden;
}

/*
  A regra [hidden] precisa continuar prevalecendo mesmo
  após definirmos display:flex.
*/
body[data-page="results"] #microbiologyList[hidden] {
  display: none !important;
}

/* Filtros não encolhem nem ocupam a altura da tabela. */
body[data-page="results"] #microbiologyList > .micro-list-toolbar {
  flex: 0 0 auto;
}

/*
  A tabela recebe somente a altura que restar.
  O rodapé passa a permanecer visível.
*/
body[data-page="results"] #microbiologyList > .users-table-layout {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;

  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;

  overflow: hidden;
}

/* Cabeçalho fixo. */
body[data-page="results"] #resultsTableHeadViewport {
  min-width: 0;
  overflow: hidden;
}

/*
  Apenas as linhas rolam vertical e horizontalmente.
*/
body[data-page="results"] #resultsTableBodyViewport {
  min-width: 0;
  min-height: 0;

  overflow-x: auto !important;
  overflow-y: auto !important;

  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

/* Rodapé com quantidade sempre visível. */
body[data-page="results"] #microbiologyList .table-footer {
  position: relative;
  z-index: 2;

  flex: 0 0 auto;

  background: #fff;
}

/* Barra de rolagem discreta, mas visível. */
body[data-page="results"] #resultsTableBodyViewport {
  scrollbar-width: thin;
  scrollbar-color: #9fc6e8 #edf5fb;
}

body[data-page="results"]
#resultsTableBodyViewport::-webkit-scrollbar {
  display: block;
  width: 8px;
  height: 8px;
}

body[data-page="results"]
#resultsTableBodyViewport::-webkit-scrollbar-track {
  background: #edf5fb;
}

body[data-page="results"]
#resultsTableBodyViewport::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #9fc6e8;
}

body[data-page="results"]
#resultsTableBodyViewport::-webkit-scrollbar-thumb:hover {
  background: #72aeda;
}

/*
  Em alturas menores, reduzimos discretamente os espaços do topo
  para entregar mais área às linhas da tabela.
*/
@media (max-height: 760px) {
  body[data-page="results"] .content.users-content.analysis-page {
    padding-top: 14px;
    padding-bottom: 12px;
  }

  body[data-page="results"] .analysis-page > .page-heading {
    margin-bottom: 10px;
  }

  body[data-page="results"] #microbiologyList {
    gap: 10px;
  }
}
