/* ====== Layout principal (wrapper + sidebar) ====== */
.wptr-layout {
  display: flex;
  gap: 1.5rem;
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  align-items: flex-start;
}

/* ====== Arquitetura base ====== */
.benz21-wrapper {
  flex: 1;
  min-width: 0;
  max-width: 760px;
  padding: 0;
  background: #ffffff;
  color: #222222;
  font-family: "Helvetica Neue", Arial, sans-serif;
}

/* Form principal (Grid) */
.benz21-form {
  display: grid;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

/* Fieldsets */
.benz21-form fieldset {
  border: 1px solid #d0d0d0;
  padding: 1rem;
  border-radius: 6px;
}

.benz21-form legend {
  font-weight: 600;
  padding: 0 0.5rem;
}

/* Campos */
.benz21-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.benz21-field label {
  font-weight: 600;
}

.benz21-field input,
.benz21-field textarea {
  border: 1px solid #bdbdbd;
  border-radius: 4px;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  line-height: 1.6;
  font-family: "Helvetica Neue", Arial, sans-serif;
}

/* Validação */
.benz21-field input[aria-invalid="true"],
.benz21-field textarea[aria-invalid="true"] {
  border-color: #c53030;
  box-shadow: 0 0 0 1px rgba(197, 48, 48, 0.2);
}

.benz21-error {
  color: #c53030;
  font-size: 0.875rem;
  margin: 0;
}

/* Alertas */
.benz21-alert {
  background: #fff5f5;
  border-left: 4px solid #e53e3e;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

/* Botões */
.benz21-button {
  background: #2563eb;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease-in-out;
}

.benz21-button:hover,
.benz21-button:focus {
  background: #1d4ed8;
  outline: none;
}

/* Primário e Secundário (hierarquia) */
.benz21-button-primary { background: #2563eb; }
.benz21-button-primary:hover,
.benz21-button-primary:focus { background: #1d4ed8; }

.benz21-button-secondary { background: #10b981; }
.benz21-button-secondary:hover,
.benz21-button-secondary:focus { background: #059669; }

/* Tabela (caso use no futuro) */
.benz21-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.benz21-table th,
.benz21-table td {
  border: 1px solid #d4d4d4;
  padding: 0.6rem 0.75rem;
  text-align: left;
}

.benz21-table thead th {
  background: #f1f5f9;
  font-weight: 600;
}

/* Toolbar + hints */
.benz21-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: .25rem 0 .5rem;
}

.benz21-hint {
  color: #64748b;
  font-size: 0.875rem;
}

/* Ações (linha de botões principais) */
.benz21-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

/* Preview de imagem (OCR) */
.benz21-image-preview {
  margin-top: .5rem;
}

.benz21-image-preview img {
  max-width: 100%;
  height: auto;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}

/* Textarea de entrada - mesma fonte da saída */
#wptr-input {
  font-family: "Helvetica Neue", Arial, sans-serif !important;
  font-size: 1rem !important;
  line-height: 1.6 !important;
}

/* Output area (suporta HTML formatado) */
.benz21-output-area {
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
  border: 1px solid #bdbdbd;
  border-radius: 4px;
  padding: 0.6rem 0.75rem;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  background: #ffffff;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.benz21-output-area:empty:before {
  content: attr(data-placeholder);
  color: #9ca3af;
  font-style: italic;
}

.benz21-output-area:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.benz21-output-area p {
  margin: 0 0 1em 0;
}

.benz21-output-area p:last-child {
  margin-bottom: 0;
}

.benz21-output-area strong {
  font-weight: 700;
  color: #1f2937;
}

.benz21-output-area em {
  font-style: italic;
}

/* Responsividade */
@media (max-width: 640px) {
  .benz21-form { gap: 1rem; }

  /* Tabela responsiva -> cards */
  .benz21-table thead { display: none; }
  .benz21-table tr {
    display: block;
    margin-bottom: 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
  }
  .benz21-table td {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border: none;
    border-bottom: 1px solid #e5e7eb;
  }
  .benz21-table td::before {
    content: attr(data-label);
    font-weight: 600;
    margin-right: 0.5rem;
  }
}

/* ====== Painel de Histórico (Sidebar) ====== */
.wptr-history-panel {
  width: 300px;
  flex-shrink: 0;
  background: #ffffff;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  font-family: "Helvetica Neue", Arial, sans-serif;
  color: #222222;
  position: sticky;
  top: 1.5rem;
}

.wptr-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fafc;
  border-radius: 6px 6px 0 0;
}

.wptr-history-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #1f2937;
}

.wptr-history-clear {
  background: none;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
}

.wptr-history-clear:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #c53030;
}

.wptr-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}

.wptr-history-list li {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.85rem;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s;
}

.wptr-history-list li:last-child {
  border-bottom: none;
}

.wptr-history-list li:hover:not(.wptr-history-empty) {
  background: #eff6ff;
}

.wptr-history-list li.wptr-history-active {
  background: #dbeafe;
  border-left: 3px solid #2563eb;
}

.wptr-history-empty {
  color: #9ca3af;
  font-style: italic;
  cursor: default !important;
  text-align: center;
  padding: 1.5rem 1rem !important;
}

.wptr-history-item-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.wptr-history-item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #374151;
}

.wptr-history-item-type {
  flex-shrink: 0;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-weight: 500;
}

.wptr-history-item-type.type-text {
  background: #dbeafe;
  color: #1d4ed8;
}

.wptr-history-item-type.type-exams {
  background: #d1fae5;
  color: #059669;
}

.wptr-history-item-time {
  display: block;
  font-size: 0.7rem;
  color: #9ca3af;
  margin-top: 0.15rem;
}

/* Preview do histórico */
.wptr-history-preview {
  border-top: 1px solid #d0d0d0;
}

.wptr-history-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: #f8fafc;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}

.wptr-history-preview-close {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: #94a3b8;
  padding: 0;
  line-height: 1;
}

.wptr-history-preview-close:hover {
  color: #c53030;
}

.wptr-history-preview-content {
  padding: 0.75rem 1rem;
  max-height: 250px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  border-top: 1px solid #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
}

.wptr-history-preview-content p {
  margin: 0 0 0.6em 0;
}

.wptr-history-preview-content p:last-child {
  margin-bottom: 0;
}

.wptr-history-preview-content strong {
  font-weight: 700;
  color: #1f2937;
}

.wptr-history-preview-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
}

.wptr-history-copy-btn {
  font-size: 0.8rem !important;
  padding: 0.4rem 0.8rem !important;
}

/* Responsividade - Sidebar */
@media (max-width: 900px) {
  .wptr-layout {
    flex-direction: column;
  }

  .wptr-history-panel {
    width: 100%;
    position: static;
    order: 1;
  }

  .benz21-wrapper {
    order: 0;
    max-width: 100%;
  }
}

/* Impressão */
@media print {
  .benz21-button,
  .benz21-actions { display: none !important; }

  .benz21-wrapper { padding: 0; }

  .wptr-history-panel { display: none !important; }
}
