:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #d1d5db;
  --primary: #1e3a8a;
  --primary-soft: #e0e7ff;
  --danger: #b91c1c;
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}

.topbar {
  padding: 1.2rem 1.6rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  color: #fff;
  border-bottom: 3px solid #cbd5e1;
}

.topbar h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.1rem, 1.8vw, 1.6rem);
}

.topbar p {
  margin: 0;
  color: #dbeafe;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(420px, 1.1fr);
  gap: 1rem;
  padding: 1rem;
  max-width: 1600px;
  margin: 0 auto;
}

.panel-form,
.panel-preview {
  min-width: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  padding: 1rem;
}

.card h2 {
  margin-top: 0;
  font-size: 1rem;
  border-left: 4px solid var(--primary);
  padding-left: 0.55rem;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: 0.8rem;
}

.two-cols {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.full {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.93rem;
  color: #334155;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.62rem 0.68rem;
  font: inherit;
  color: var(--text);
  background: #fff;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid #bfdbfe;
  border-color: #93c5fd;
}

.hint {
  margin-top: -0.4rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.dynamic-list {
  display: grid;
  gap: 0.65rem;
}

.dynamic-item {
  background: #f8fafc;
  border: 1px dashed #b6c2d4;
  border-radius: 10px;
  padding: 0.65rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  align-items: end;
}

.dynamic-fields {
  display: grid;
  gap: 0.55rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dynamic-fields.single {
  grid-template-columns: 1fr;
}

.evaluacion-grid {
  display: grid;
  gap: 0.6rem;
}

.eval-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  background: #fafcff;
}

.eval-row strong {
  display: block;
  margin-bottom: 0.45rem;
}

.score-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.score-options label,
.stack label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.92rem;
  margin-right: 0.5rem;
}

.stack {
  margin-bottom: 0.6rem;
}

.btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 8px;
  padding: 0.58rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: #334155;
}

.btn:hover {
  filter: brightness(0.98);
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: #1e40af;
}

.btn.secondary {
  background: var(--primary-soft);
  border-color: #c7d2fe;
  color: #1e3a8a;
}

.btn.danger {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}

.actions {
  position: sticky;
  bottom: 0;
  padding: 0.8rem;
  background: rgba(244, 246, 249, 0.95);
  backdrop-filter: blur(4px);
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.preview-toolbar h2 {
  margin: 0 0 0.7rem;
  color: #0f172a;
  font-size: 1.02rem;
}

.acta {
  background: #fff;
  border: 1px solid #cbd5e1;
  box-shadow: var(--shadow);
  border-radius: 8px;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto 1rem;
  padding: 15mm;
}

.acta-header {
  text-align: center;
  margin-bottom: 0.7rem;
}

.acta-header h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.2px;
}

.acta h3 {
  margin: 0.95rem 0 0.35rem;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.2rem;
  font-size: 0.98rem;
}

.table-info,
.table-score {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.89rem;
  table-layout: fixed;
}

.table-info th,
.table-info td,
.table-score th,
.table-score td {
  border: 1px solid #dbe2ea;
  padding: 0.4rem 0.45rem;
  vertical-align: top;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.table-info th {
  width: 30%;
  background: #f8fafc;
  text-align: left;
}

/* La URL puede ser muy larga: forzamos quiebre dentro de la celda */
.table-info td a {
  word-break: break-all;
  overflow-wrap: anywhere;
}

/* ===== Firmas (lado a lado, con espacio para sello) ===== */
.firmas {
  margin-top: 2.6rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 2rem;
}

.firma-box {
  flex: 1 1 0;
  text-align: center;
  font-size: 0.84rem;
  /* Espacio superior reservado para el sello/timbre */
  padding-top: 3.2rem;
}

.firma-box .firma-line {
  display: block;
  border-top: 1px solid #1f2937;
  margin: 0 auto 0.4rem;
  width: 80%;
}

.firma-box strong {
  display: block;
}

.firma-box small {
  display: block;
  color: var(--muted);
}

.empty-inline {
  color: #9ca3af;
  font-style: italic;
}

.validation-msg {
  margin: 0.45rem 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .acta {
    width: 100%;
    min-height: auto;
    padding: 1rem;
  }
}

@media (max-width: 780px) {
  .two-cols,
  .dynamic-fields {
    grid-template-columns: 1fr;
  }

  .dynamic-item {
    grid-template-columns: 1fr;
  }

  .firmas {
    grid-template-columns: 1fr;
  }
}

/* ===== Modo PDF: clon aislado renderizado por html2canvas ===== */
.acta-pdf-mode {
  width: 794px !important;       /* ~210mm a 96dpi */
  min-height: auto !important;
  box-shadow: none !important;
  border: none !important;
  border-radius: 0 !important;
  margin: 0 !important;
  padding: 28px !important;
  background: #ffffff !important;
  color: #1f2937 !important;
}

/* Evita cortes feos de filas/firmas entre páginas del PDF */
.acta-pdf-mode tr,
.acta-pdf-mode .firma-box,
.acta-pdf-mode .acta-header,
.acta-pdf-mode h3 {
  page-break-inside: avoid;
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body {
    background: #fff;
  }

  .no-print,
  .panel-form,
  .preview-toolbar {
    display: none !important;
  }

  .layout {
    display: block;
    padding: 0;
    max-width: none;
  }

  .panel-preview {
    width: 100%;
  }

  .acta {
    border: none;
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    width: auto;       /* se ajusta al área imprimible (evita desbordes) */
    max-width: 100%;
    min-height: auto;
    padding: 0;
  }

  /* Evita que tablas y firmas se corten entre páginas */
  .acta tr,
  .firma-box,
  .acta h3 {
    page-break-inside: avoid;
  }

  .firmas {
    page-break-inside: avoid;
  }
}
