/* NES — Receituário Farmacêutico Inteligente */

.rx-inteligente .rx-int-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.rx-int-header {
  flex-wrap: wrap;
  gap: 12px;
}

.rx-int-form {
  max-width: 100%;
}

.rx-table-wrap {
  overflow-x: auto;
  margin-top: 8px;
}

.rx-table-compact {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  min-width: 1100px;
}

.rx-table-compact th,
.rx-table-compact td {
  border: 1px solid #cfe2dc;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.rx-table-compact th {
  background: #eef6f3;
  font-weight: 700;
  color: #0f4c66;
  white-space: nowrap;
}

.rx-table-compact tbody tr:nth-child(even) {
  background: #f8fbfa;
}

.rx-cell-acoes {
  white-space: nowrap;
}

.rx-cell-obs {
  max-width: 120px;
}

.rx-protocolos-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rx-proto-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #e8f4f0;
  border: 1px solid #9fd4c4;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.rx-empty-hint {
  margin: 8px 0 0;
  font-size: 0.85rem;
}

.rx-txt-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.rx-int-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 0 24px;
}

/* Modais */
.rx-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 12000;
  background: rgba(15, 76, 102, 0.45);
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}

.rx-modal-backdrop.open {
  display: flex;
}

.rx-modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  margin: auto;
}

.rx-modal-lg {
  max-width: 960px;
}

/* ── Modal de item da prescrição (largura máxima, flex coluna, rolagem interna) ── */
.rx-modal-item {
  width: min(1100px, 96vw) !important;
  max-width: none !important;
  max-height: 92vh !important;
  display: flex !important;
  flex-direction: column !important;
  margin: auto !important;
}

/* Quando o backdrop tiver o modal de item, centralizar verticalmente */
#rx-modal-item-backdrop {
  align-items: center !important;
  overflow-y: hidden !important;
}

/* Área de conteúdo com rolagem */
.rx-modal-item .rx-modal-body {
  flex: 1 1 auto !important;
  overflow-y: auto !important;
  max-height: none !important;
  padding: 20px 24px !important;
}

/* Rodapé fixo na base do modal */
.rx-modal-item .rx-modal-footer {
  position: sticky !important;
  bottom: 0 !important;
  background: #fff !important;
  border-top: 2px solid #dbe7ef !important;
  z-index: 10 !important;
  flex-shrink: 0 !important;
  padding: 14px 24px !important;
}

/* ── Seções dentro do formulário de item ── */
.rx-item-secao {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.rx-item-secao-titulo {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #0f4c66;
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #dbe7ef;
}

/* Grid 3 colunas para campos curtos */
.rx-item-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 16px;
}

/* Grid 2 colunas padrão */
.rx-item-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}

/* Campos do modal Editar item */
.rx-modal-item .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 20px;
}

.rx-modal-item .form-grid label,
.rx-modal-item > .rx-modal-body > label,
.rx-item-secao label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #374151;
}

.rx-modal-item .form-grid label input,
.rx-modal-item .form-grid label select,
.rx-modal-item .form-grid label textarea,
.rx-modal-item .rx-modal-body label input,
.rx-modal-item .rx-modal-body label select,
.rx-modal-item .rx-modal-body label textarea,
.rx-item-secao label input,
.rx-item-secao label select,
.rx-item-secao label textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 400;
  color: #111;
  background: #f9fafb;
  transition: border-color 0.15s;
  font-family: inherit;
}

.rx-modal-item .rx-modal-body label input:focus,
.rx-modal-item .rx-modal-body label select:focus,
.rx-modal-item .rx-modal-body label textarea:focus,
.rx-item-secao label input:focus,
.rx-item-secao label select:focus,
.rx-item-secao label textarea:focus {
  outline: none;
  border-color: #0f4c66;
  background: #fff;
}

/* Campo de observações */
.rx-modal-item .rx-modal-body > label {
  margin-top: 14px;
}

.rx-modal-item .rx-modal-body label textarea,
.rx-item-secao label textarea {
  resize: vertical;
  min-height: 72px;
}

/* Alerta clínico nunca cortado */
#rx-med-alerta-container {
  margin-top: 12px;
}

/* Responsivo */
@media (max-width: 700px) {
  .rx-modal-item {
    width: 100vw !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
  .rx-item-grid-3,
  .rx-item-grid-2 {
    grid-template-columns: 1fr !important;
  }
}

.rx-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #d7e5e1;
}

.rx-modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: #0f4c66;
}

.rx-modal-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
}

.rx-modal-body {
  padding: 16px 20px;
  max-height: 70vh;
  overflow-y: auto;
}

/* Preview do receituário — iframe ocupa toda a área disponível sem scroll duplo */
#rx-preview-corpo {
  padding: 0;
  max-height: 72vh;
  overflow: hidden;
}

.rx-modal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid #d7e5e1;
}

/* ════════════════════════════════════════════════════════════════════
   Modal de Alertas Clínicos — confirmação antes de salvar
   ════════════════════════════════════════════════════════════════════ */

/* Backdrop centraliza verticalmente (diferente do padrão flex-start) */
.rx-alertas-salvar-backdrop {
  align-items: center !important;
  padding: 20px !important;
}

.rx-alertas-salvar-modal {
  max-width: 620px !important;
  width: 100% !important;
  border-radius: 16px !important;
  box-shadow: 0 24px 64px rgba(0,0,0,.35) !important;
  animation: rx-alertas-entrada .18s ease-out both;
}

@keyframes rx-alertas-entrada {
  from { opacity: 0; transform: scale(.94) translateY(-8px); }
  to   { opacity: 1; transform: scale(1)  translateY(0); }
}

/* Cabeçalho com ícone grande */
.rx-alertas-header {
  background: #fff8f0;
  border-bottom: 2px solid #fed7aa !important;
  border-radius: 16px 16px 0 0;
  gap: 10px;
  padding: 18px 22px !important;
}

.rx-alertas-icone {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.rx-alertas-header h3 {
  color: #92400e !important;
  font-size: 1.05rem !important;
  margin: 0 !important;
}

/* Corpo com scroll */
.rx-alertas-body {
  max-height: 55vh;
  overflow-y: auto;
  padding: 20px 22px !important;
}

.rx-alertas-subtitulo {
  font-size: .9rem;
  color: #374151;
  margin: 0 0 14px;
  line-height: 1.5;
}

/* Cards por alerta */
.rx-alerta-card {
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.rx-alerta-card--vermelho {
  border-color: #fca5a5;
  background: #fef2f2;
}

.rx-alerta-card--amarelo {
  border-color: #fcd34d;
  background: #fffbeb;
}

.rx-alerta-card-topo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.rx-alerta-card-icone {
  font-size: 1rem;
  flex-shrink: 0;
}

.rx-alerta-card-nome {
  font-size: .95rem;
  color: #1f2937;
}

.rx-alerta-card-corpo {
  padding-left: 28px;
}

.rx-alerta-row {
  font-size: .82rem;
  color: #4b5563;
  margin-bottom: 3px;
  line-height: 1.4;
}

.rx-alerta-monitor {
  color: #b45309;
  font-weight: 600;
}

.rx-alerta-exames {
  color: #1d4ed8;
}

/* Checkbox "ciente" */
.rx-alertas-ciente {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  padding: 12px 14px;
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 8px;
  cursor: pointer;
  font-size: .88rem;
  color: #166534;
  line-height: 1.4;
}

.rx-alertas-ciente input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #166534;
}

/* Rodapé dos botões */
.rx-alertas-footer {
  background: #f9fafb !important;
  border-top: 1px solid #e5e7eb !important;
  padding: 14px 22px !important;
  border-radius: 0 0 16px 16px;
  justify-content: flex-start !important;
  gap: 10px !important;
}

#rx-btn-continuar-salvar {
  background: #0f4c66;
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

#rx-btn-continuar-salvar:hover:not(:disabled) { background: #0a3a50; }

#rx-btn-continuar-salvar:disabled {
  opacity: .45;
  cursor: not-allowed;
}

#rx-btn-revisar-prescricao {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: .9rem;
}

@media (max-width: 500px) {
  .rx-alertas-salvar-modal { border-radius: 12px 12px 0 0 !important; }
  .rx-alertas-salvar-backdrop { align-items: flex-end !important; padding: 0 !important; }
}

/* ──────────────────────────────────────────────────────────────────── */

.rx-modal-busca {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 0.95rem;
  box-sizing: border-box;
}

.rx-modal-busca-hint {
  margin: 6px 0 12px;
  font-size: 0.8rem;
}

.rx-filtros-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.rx-filtro-chip {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  cursor: pointer;
}

.rx-filtro-chip.active {
  background: #0f4c66;
  color: #fff;
  border-color: #0f4c66;
}

.rx-modal-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.rx-proto-card {
  border: 1px solid #d7e5e1;
  border-radius: 14px;
  padding: 14px;
  background: #fafcfb;
}

.rx-proto-card h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: #0f4c66;
}

.rx-proto-meta {
  font-size: 0.78rem;
  color: #64748b;
  margin: 0 0 8px;
}

.rx-proto-resumo {
  font-size: 0.82rem;
  color: #334155;
  margin: 0 0 10px;
  line-height: 1.4;
}

.rx-badge {
  display: inline-block;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 6px;
  margin-left: 6px;
}

.rx-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.rx-tag {
  font-size: 0.7rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 2px 6px;
}

@media (max-width: 768px) {
  .rx-int-toolbar .btn,
  .rx-int-footer-actions .btn {
    flex: 1 1 auto;
    min-width: 140px;
    min-height: 44px;
  }

  .rx-int-footer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    position: sticky;
    bottom: 0;
    background: #f8fafc;
    padding: 12px 0;
    z-index: 2;
  }

  #receituario-farmaceutico-view .page-content {
    padding-bottom: 24px;
  }

  .rx-modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .rx-modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    margin: 0;
    display: flex;
    flex-direction: column;
  }

  .rx-modal-body {
    flex: 1 1 auto;
    max-height: calc(90vh - 120px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .rx-modal-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    z-index: 2;
  }

  .rx-modal-footer .btn,
  .rx-modal-close {
    min-height: 44px;
    min-width: 44px;
  }

  .pront-quick-rail [data-action-rec] {
    min-height: 44px;
    width: 100%;
  }
}

/* Modal fullscreen Biblioteca de Protocolos no receituário */
.rx-modal-proto-fullscreen {
  width: 90vw;
  max-width: 90vw;
  height: 92vh;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  margin: auto;
}

.rx-proto-modal-body {
  flex: 1 1 auto;
  max-height: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 12px 20px 16px;
}

.rx-proto-toolbar {
  flex-shrink: 0;
  margin-bottom: 12px;
}

.rx-proto-filter {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  font-weight: 600;
}

.rx-proto-split {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(240px, 360px) 1fr;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.rx-proto-list {
  overflow-y: auto;
  border: 1px solid #d7e5e1;
  border-radius: 12px;
  padding: 8px;
  background: #f8fbfa;
}

.rx-proto-list-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
}

.rx-proto-list-item.active,
.rx-proto-list-item:hover {
  border-color: #16846f;
  background: #eef9f5;
}

.rx-proto-list-sub {
  display: block;
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 4px;
}

.rx-proto-preview {
  overflow-y: auto;
  border: 1px solid #d7e5e1;
  border-radius: 12px;
  padding: 16px;
  background: #fff;
}

.rx-proto-itens-mini {
  font-size: 0.82rem;
  padding-left: 18px;
}

.rx-proto-footer {
  flex-shrink: 0;
}

.rx-alerta-cabecalho {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff7ed;
  border: 1px solid #fdba74;
}

.rx-alerta-cabecalho .alerta-clinico-paciente {
  margin: 0;
}

.rx-paciente-hint {
  margin: 0 0 8px;
  font-size: 0.88rem;
}

@media (max-width: 768px) {
  .rx-modal-proto-fullscreen {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .rx-proto-split {
    grid-template-columns: 1fr;
  }
}
