:root {
  --ink: #171411;
  --muted: #6f6963;
  --paper: #fff;
  --canvas: #eeeae5;
  --line: #d9d2cb;
  --accent: #b7935f;
  --offset-x: 0mm;
  --offset-y: 0mm;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: Montserrat, Arial, sans-serif;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 92px;
  padding: 22px clamp(20px, 4vw, 54px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  background: var(--ink);
}
.eyebrow { margin: 0 0 3px; color: #d3b98e; font-size: 11px; font-weight: 600; letter-spacing: .24em; }
h1 { margin: 0; font-size: clamp(21px, 3vw, 31px); font-weight: 500; }
.ghost { padding: 10px 14px; color: white; background: transparent; border: 1px solid #5f5851; border-radius: 10px; }

.workspace {
  width: min(1450px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 3vw, 40px);
  display: grid;
  grid-template-columns: minmax(300px, .72fr) minmax(520px, 1.28fr);
  gap: 24px;
}
.panel { background: var(--paper); border: 1px solid #e2ddd8; border-radius: 20px; padding: clamp(20px, 3vw, 34px); box-shadow: 0 14px 40px rgba(33,26,18,.06); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 26px; }
.section-heading > div { display: flex; align-items: baseline; gap: 10px; }
.section-heading h2 { margin: 0; font-size: 21px; font-weight: 600; }
.step { color: var(--accent); font-size: 12px; font-weight: 600; letter-spacing: .1em; }
.status { white-space: nowrap; padding: 6px 9px; border-radius: 99px; background: #f3efe9; color: #695d4d; font-size: 10px; font-weight: 600; }

label, legend { color: #3d3834; font-size: 12px; font-weight: 600; letter-spacing: .03em; }
input, textarea {
  width: 100%; margin-top: 8px; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 13px; color: var(--ink); background: #fff; font-size: 15px; font-weight: 400; outline: none;
}
input:focus, textarea:focus { border-color: #8d7658; box-shadow: 0 0 0 3px rgba(183,147,95,.14); }
textarea { resize: vertical; min-height: 100px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.counter { display: block; margin: 5px 2px 20px; text-align: right; color: var(--muted); font-size: 10px; font-weight: 400; }
fieldset { margin: 0; padding: 0; border: 0; }
.hint { margin: 4px 0 12px; color: var(--muted); font-size: 11px; }
.service-row { display: grid; grid-template-columns: 1fr 38px; gap: 8px; margin-bottom: 9px; }
.service-row input { margin: 0; }
.remove-service { border: 1px solid var(--line); border-radius: 9px; background: #fff; color: #857b72; font-size: 18px; }
.text-button { padding: 8px 0; border: 0; background: transparent; color: #796246; font-size: 12px; font-weight: 600; }
.date-card { margin-top: 18px; padding: 14px 16px; border-radius: 12px; background: #f4f1ed; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.date-card span { color: var(--muted); font-size: 11px; }
.date-card strong { grid-row: span 2; align-self: center; font-size: 15px; }
.date-card small { color: #8a8179; font-size: 9px; }

.preview-stage { min-height: 315px; display: grid; place-items: center; overflow: hidden; border-radius: 14px; background: #25211e; padding: 25px; }
.certificate { position: relative; width: min(100%, 900px); aspect-ratio: 21.82 / 9.29; background: white; overflow: hidden; box-shadow: 0 16px 35px #0006; }
.certificate > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.print-area, .print-content {
  position: absolute;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  color: #151515; font-family: Montserrat, Arial, sans-serif; overflow: hidden;
}
.certificate .print-area {
  /* Porcentajes para que la vista previa mantenga el calce al redimensionarse. */
  left: 4.2%; top: 34.8%; width: 39%; height: 61%;
  transform-origin: top left;
}
.print-content {
  /* Coordenadas físicas utilizadas únicamente por la impresora. */
  left: 9.1mm; top: 32.3mm; width: 85mm; height: 56.8mm;
}
.line { margin: 0; line-height: 1.15; }
.label { font-size: .62em; font-weight: 500; letter-spacing: .08em; }
.from-line { font-size: clamp(7px, 1.18vw, 13px); }
.to-line { margin-top: 1.2mm; font-size: clamp(8px, 1.35vw, 15px); font-weight: 500; }
.message { width: 82mm; max-width: 86%; margin: 3.1mm 0 0; line-height: 1.17; font-size: clamp(6.5px, 1.05vw, 12px); white-space: pre-wrap; }
.services { width: 100%; margin-top: 1.8mm; display: flex; flex: 1 1 auto; flex-direction: column; justify-content: center; gap: .7mm; min-height: 0; font-size: clamp(7px, 1.25vw, 14px); font-weight: 500; line-height: 1.06; text-transform: uppercase; }
.service { margin: 0; }
.services.compact { font-size: clamp(6px, 1.02vw, 11px); }
.expiry { flex: 0 0 auto; margin: 1.2mm 0 1mm; font-size: clamp(5.5px, .78vw, 9px); line-height: 1; }

.calibration { margin-top: 18px; border-top: 1px solid #e9e4df; padding-top: 15px; }
.calibration summary { color: #4f4841; font-size: 12px; font-weight: 600; cursor: pointer; }
.calibration p { color: var(--muted); font-size: 10px; line-height: 1.5; }
.calibration .form-grid { margin-bottom: 0; }
.actions { display: grid; grid-template-columns: 1fr 1.35fr; gap: 12px; margin-top: 22px; }
.actions button { min-height: 48px; border-radius: 11px; font-weight: 600; }
.secondary { border: 1px solid #b8aea4; background: white; color: #3e3832; }
.primary { border: 1px solid var(--ink); background: var(--ink); color: white; }
.notice { min-height: 16px; margin: 10px 0 0; color: #9b352e; font-size: 11px; text-align: center; }

#printSheet { display: none; }

@media (max-width: 920px) {
  .workspace { grid-template-columns: 1fr; }
  .preview-panel { grid-row: 1; }
}
@media (max-width: 580px) {
  .topbar { min-height: 76px; }
  .workspace { padding: 12px; gap: 12px; }
  .panel { padding: 18px; border-radius: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .preview-stage { min-height: 190px; padding: 12px; }
  .actions { grid-template-columns: 1fr; }
}

@page { size: 218.2mm 92.9mm; margin: 0; }
@media print {
  html, body { width: 218.2mm; height: 92.9mm; margin: 0 !important; padding: 0 !important; background: white; overflow: hidden; }
  body > *:not(#printSheet) { display: none !important; }
  #printSheet { display: block !important; position: relative; width: 218.2mm; height: 92.9mm; }
  .print-content { transform: translate(var(--offset-x), var(--offset-y)); }
  .print-content .from-line { font-size: 13pt; }
  .print-content .to-line { font-size: 15pt; }
  .print-content .message { font-size: 11pt; }
  .print-content .services { font-size: 14pt; }
  .print-content .services.compact { font-size: 11pt; }
  .print-content .expiry { font-size: 9pt; }
}
