/* Body Styles */
html {
  scrollbar-gutter: stable;
}

/* Base (fuente Inter, colores, cabecera) en style.css, de la plantilla 226ERS. */
body {
  background-color: var(--bg-app);
}

.hidden {
  display: none !important;
}

/* Main Content Styles */
#principal {
  background: var(--bg-card);
  padding: 40px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  text-align: center;
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

/* Drag and drop onto the file card */
#principal {
  border: 2px dashed var(--border-focus);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

#principal.dragOver {
  border-color: var(--brand);
  background-color: var(--brand-light);
}

#dropHint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  margin-bottom: 14px;
  font-weight: 500;
}

#dropHint svg {
  color: var(--brand);
  margin-bottom: 4px;
}

#principal.dragOver #dropHint {
  color: var(--brand);
}

.dropOr {
  font-size: 0.85em;
  font-weight: 400;
}

/* File Input Styles */
input[type="file"] {
  display: none;
}

/* Label Styles */
label {
  cursor: pointer;
  background-color: var(--brand);
  color: #fff;
  padding: 10px 20px;
  border-radius: 5px;
  transition: background-color 0.3s ease;
  margin-bottom: 20px;
  display: inline-block;
}

label:hover {
  background-color: var(--brand-hover);
}

/* Button Styles */
button {
  background-color: #2563eb;
  color: #fff;
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  margin: 10px 0;
  font-family: var(--font-sans);
}

button:disabled {
  background-color: #cccccc;
  cursor: not-allowed;
}

button:hover:not(:disabled) {
  background-color: #1d4ed8;
}

.ghostButton {
  background: none;
  color: #666;
  padding: 6px 10px;
  margin: 0;
}

.ghostButton:hover:not(:disabled) {
  background-color: #eee;
}

/* PDF Preview / Viewer Styles */
.pdfPreview {
  border: 1px solid #ccc;
  margin-bottom: 20px;
  border-radius: 5px;
  overflow: hidden;
  transition: box-shadow 0.3s ease;
}

.pdfPreview iframe {
  width: 100%;
  height: 400px;
  border: none;
  border-radius: 5px;
}

.pdfPreview:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Button Styles (secondary/download) */
.pdfButton {
  background-color: #2563eb;
  color: #fff;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.pdfButton:hover:not(:disabled) {
  background-color: #1d4ed8;
}

.pdfButton:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Loader Styles */
.loader {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3498db;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 20px auto;
  display: none;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Title Styles */
h1 {
  margin-top: 0;
  color: #333;
  font-size: 1.5em;
}

/* Paragraph Styles */
p {
  color: #666;
  font-size: 1em;
  margin-bottom: 20px;
}

/* Error Message Styles */
.error {
  color: #ff6347;
  font-size: 0.9em;
  margin-top: 10px;
}

/* Viewer Styles */
#viewerSection {
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 900px;
  margin: 20px auto 0;
  box-sizing: border-box;
}

#viewerHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

#viewerFileName {
  color: #333;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#viewerPreview {
  margin-bottom: 0;
}

#viewerPreview iframe {
  height: 60vh;
}

#viewerActions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-top: 15px;
}

.actionGroup {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.actionTitle {
  font-size: 0.8em;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#downloadRow {
  display: flex;
  align-items: center;
  gap: 10px;
}

#targetFormat, #saveFormat {
  font-family: var(--font-sans);
  padding: 8px 12px;
  border-radius: 5px;
  border: 1px solid #ccc;
  background-color: #fff;
  cursor: pointer;
}

#editButton { background-color: #ffffff; color: #2563eb; border: 1px solid #2563eb; border-radius: 6px; padding: 10px 20px; font-weight: 500; cursor: pointer; transition: all 0.2s; }

#editButton:hover { background-color: #eff6ff; }

/* Editor Styles: full-screen takeover, page-style sheet like a PDF viewer */
body.editorOpen {
  overflow: hidden;
}

#editorSection {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #525659;
  display: flex;
  flex-direction: row;
}

#editorSidebar {
  width: 320px;
  background: #fff;
  border-right: 1px solid #ccc;
  display: flex;
  flex-direction: column;
  padding: 20px;
  box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  z-index: 10;
  flex-shrink: 0;
}

#sidebarHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

#sidebarHeader h3 {
  margin: 0;
  font-size: 1.2em;
  color: #333;
}

#editorHint {
  font-size: 0.9em;
  color: #666;
  margin-bottom: 24px;
}

#sidebarTools {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#typographyControls {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0 12px 12px 12px;
  margin-top: 10px;
}

.formatting-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.formatting-row:last-child {
  margin-bottom: 0;
}

.format-select {
  flex: 1;
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  min-width: 0; /* allows shrinking */
}

.format-input {
  width: 50px;
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
}

.format-btn {
  flex: 1;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 6px 0;
  cursor: pointer;
  font-size: 14px;
  color: #333;
  transition: all 0.2s;
  font-family: serif; /* nice for B/I */
}

.format-btn:hover {
  background: #f0f0f0;
}

.format-btn.active {
  background: #0099ff;
  color: #fff;
  border-color: #0099ff;
}

.format-color {
  width: 40px;
  height: 32px;
  padding: 0;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

.toolbarButton { width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: #ffffff; border: 1px solid #e5e7eb; border-radius: 6px; color: #374151; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.2s; box-sizing: border-box; text-align: left; }


.toolbarButton:hover {
  background: #e1e8f0;
  border-color: #c0c8d0;
}

/* Specific overrides for certain buttons */
#signatureButton {
  background-color: #0099ff;
  color: #fff;
  border-color: #0099ff;
}
#signatureButton:hover {
  background-color: #007acc;
  border-color: #007acc;
}

.editorCloseButton {
  background-color: #ffe0e0;
  color: #c0392b;
  border: none;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9em;
}
.editorCloseButton:hover {
  background-color: #ffcccc;
}

#sidebarFooter {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

#saveEditButton {
  width: 100%;
  margin: 0;
  padding: 12px;
  font-size: 1.05em;
}

#editorMain {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#editorScroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 32px 16px 60px;
}

#editorPages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* One rendered PDF page: the redacted (text-free) render as background,
   with editable text boxes absolutely positioned to match the original. */
.layoutPage {
  position: relative;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.layoutPage > img.pageBackground {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
}

.toolbarButton { width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: #ffffff; border: 1px solid #e5e7eb; border-radius: 6px; color: #374151; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.2s; box-sizing: border-box; text-align: left; }
.toolbarButton:hover { background: #f9fafb; border-color: #d1d5db; color: #111827; }

/* A draggable/resizable image placed on the page (extracted from the PDF,
   or newly added by the user). */
.layoutImage, .layoutLink {
  position: absolute;
  cursor: move;
  border: 1px dashed transparent;
  box-sizing: border-box;
}

.layoutLink {
  border: 2px dashed #0099ff;
  background: rgba(0, 153, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.layoutLink input {
  width: 90%;
  padding: 4px;
  font-size: 12px;
  border: 1px solid #0099ff;
  border-radius: 4px;
  text-align: center;
  cursor: text;
  background: rgba(255, 255, 255, 0.9);
}

.layoutImage.selected, .layoutLink.selected {
  border-color: rgba(0, 153, 255, 0.8);
  z-index: 2;
}

.layoutImage img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
}

.imageDeleteButton {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e74c3c;
  color: #fff;
  border: 2px solid #fff;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.layoutImage.selected .imageDeleteButton, .layoutLink.selected .imageDeleteButton {
  display: flex;
}

.imageDeleteButton:hover {
  background: #c0392b;
}

.imageResizeHandle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: #0099ff;
  border: 2px solid #fff;
  cursor: nwse-resize;
  display: none;
}

.layoutImage.selected .imageResizeHandle, .layoutLink.selected .imageResizeHandle {
  display: block;
}

.layoutSpan {
  position: absolute;
  /* Wraps like a normal text box; relayoutPage() pushes what's below out of
     the way if that makes it taller. nowrap would instead force a long new
     line to render as one unbroken (and unreadable once shrunk) strip. */
  white-space: pre-wrap;
  overflow: visible;
  overflow-wrap: break-word;
  line-height: 1.15;
  cursor: text;
  border: 1px dashed transparent;
  border-radius: 2px;
  padding: 0 1px;
  font-family: Arial, Helvetica, sans-serif;
  transform-origin: left top;
}

/* A paragraph being edited as one flowing box (see convertToFlow in
   index.js). Same 1px border + horizontal padding as .layoutSpan, so the
   text stays exactly in place when its lines are swapped for this box. */
.layoutFlow {
  position: absolute;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  cursor: text;
  border: 1px dashed transparent;
  border-radius: 2px;
  padding-right: 1px;
  outline: none;
  z-index: 1;
}

.layoutFlow:focus {
  border-color: #0099ff;
  background: rgba(0, 153, 255, 0.06);
}

.layoutSpan:focus {
  outline: none;
  border-color: #0099ff;
  background: rgba(0, 153, 255, 0.06);
}

/* Lets a text box be dragged anywhere on the page (e.g. up into empty space
   above it), without living inside the contenteditable span itself - see the
   note in index.js about span.el.innerText picking up stray children. */
.spanDragHandle {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: #0099ff;
  border: 2px solid #fff;
  cursor: move;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

.spanDragHandle.visible,
.spanDragHandle.dragging {
  opacity: 1;
  pointer-events: auto;
}



/* ── Signature pad modal ── */

#signatureModal {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#signatureBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

#signaturePanel {
  position: relative;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35);
  padding: 20px;
  width: min(560px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#signatureHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#signatureHeader > span {
  font-weight: 500;
  font-size: 1.1em;
  color: #333;
}

#signatureColorPicker {
  display: flex;
  gap: 6px;
}

.sigColor {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid #ddd !important;
  padding: 0 !important;
  margin: 0 !important;
  cursor: pointer;
  transition: border-color 0.15s;
}

.sigColor.selected {
  border-color: #0099ff !important;
}

.sigColor:hover:not(.selected) {
  border-color: #aaa !important;
}

#signatureCanvas {
  width: 100%;
  height: 200px;
  border: 2px solid #ddd;
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
  background:
    linear-gradient(transparent 85%, rgba(0, 0, 0, 0.04) 85%, rgba(0, 0, 0, 0.04) 87%, transparent 87%);
}

#signatureActions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sigSpacer {
  flex: 1;
}

.sigSecondary {
  background: #f0f0f0 !important;
  color: #333 !important;
  padding: 8px 16px !important;
  font-size: 0.9em;
}

.sigSecondary:hover:not(:disabled) {
  background: #e0e0e0 !important;
}

.sigAccept {
  background: #27ae60 !important;
  color: #fff !important;
  padding: 8px 20px !important;
  font-size: 0.95em;
  font-weight: 500;
}

.sigAccept:hover:not(:disabled) {
  background: #219a52 !important;
}

/* The toolbar "Firma" button inherits the green default button style,
   give it the same blue as the "Añadir imagen" label so the toolbar
   looks consistent. */
#signatureButton {
  background-color: #0099ff;
  color: #fff;
  margin: 0;
}

#signatureButton:hover:not(:disabled) {
  background-color: #007acc;
}

.spanDeleteHandle {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  border: 2px solid #fff;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
}
.spanDeleteHandle.visible {
  opacity: 1;
  pointer-events: auto;
}
.spanDeleteHandle:hover {
  background: #dc2626;
}
