:root {
  --bg-page: #ffffff;
  --text-primary: #181818;
  --text-secondary: #556270;
  --accent-primary: #0a4c8e;
  --accent-primary-hover: #083b6f;
  --accent-primary-active: #062c54;
  --accent-soft-bg: #eef4fb;
  --border-secondary: #d5dfe8;
  --border-card: rgba(10, 76, 142, 0.15);
  --preview-bg: #f4f7fa;
  --status-info-bg: #eef4fb;
  --status-info-border: #bfd4ec;
  --status-info-text: #0a3d73;
  --status-error-bg: #fdf2f2;
  --status-error-border: #e6b8b8;
  --status-error-text: #8a1f1f;
  --focus-ring: #0a4c8e;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-container {
  max-width: 940px;
  margin: 0 auto;
  padding: 28px;
  width: 100%;
  background-color: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(10, 76, 142, 0.1);
}

/* 1. Encabezado */
.app-header {
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 3px solid var(--accent-primary);
}

.app-header h1 {
  margin: 0 0 6px 0;
  font-size: 30px;
  font-weight: 600;
  color: var(--accent-primary);
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.subtitle {
  margin: 0;
  font-size: 16px;
  color: var(--text-secondary);
}

/* 2. Selección de archivos */
.file-selection {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.file-picker-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--border-secondary);
  border-radius: 10px;
  background-color: #ffffff;
  min-width: 0;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.file-picker-group:hover {
  border-color: #b5c7d9;
}

.file-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  border-radius: 6px;
  background-color: var(--accent-soft-bg);
  border: 1px solid rgba(10, 76, 142, 0.2);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-primary);
  white-space: nowrap;
}

.file-name {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  border-radius: 7px;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease,
    color 120ms ease, box-shadow 120ms ease;
}

.btn:focus-visible,
.size-slider:focus-visible,
.photo-overlay:focus-visible,
.resize-handle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn-secondary {
  background-color: #ffffff;
  color: var(--text-primary);
  border: 1px solid var(--border-secondary);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--accent-soft-bg);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-secondary:active:not(:disabled) {
  background-color: #dfeaf7;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #ffffff;
  border: 1px solid var(--accent-primary);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
}

.btn-primary:active:not(:disabled) {
  background-color: var(--accent-primary-active);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-icon {
  min-width: 42px;
  padding: 6px 10px;
  font-size: 17px;
}

/* 3. Mensajes breves de estado o error */
.status-banner {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 14px;
  border: 1px solid var(--status-info-border);
  background-color: var(--status-info-bg);
  color: var(--status-info-text);
}

.status-banner.is-error {
  border-color: var(--status-error-border);
  background-color: var(--status-error-bg);
  color: var(--status-error-text);
}

/* 4. Controles de la imagen y acciones */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  padding: 12px 14px;
  background-color: #f9fbfd;
  border: 1px solid var(--border-secondary);
  border-radius: 10px;
}

.image-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 18px;
}

.image-controls[hidden] {
  display: none !important;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-primary);
}

.size-controls,
.move-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.size-slider {
  width: 140px;
  height: 42px;
  margin: 0 4px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.action-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* 5. Vista previa */
.preview-panel {
  background-color: var(--preview-bg);
  border: 1px solid #e1e8f0;
  border-radius: 10px;
  padding: 22px 16px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
  width: 100%;
  flex-wrap: wrap;
}

.pagination-bar[hidden] {
  display: none !important;
}

.page-indicator {
  font-size: 14px;
  color: var(--accent-primary);
  font-weight: 600;
}

.btn-page {
  padding: 6px 12px;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
}

.empty-state[hidden] {
  display: none !important;
}

.empty-title {
  margin: 0 0 6px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent-primary);
}

.empty-subtitle {
  margin: 0;
  font-size: 15px;
  color: var(--text-secondary);
}

.stage-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
}

.stage-wrapper[hidden] {
  display: none !important;
}

.pdf-stage {
  position: relative;
  width: 100%;
  max-width: 640px;
  background-color: #ffffff;
  box-shadow: 0 4px 16px rgba(10, 76, 142, 0.12);
  line-height: 0;
  user-select: none;
  touch-action: manipulation;
  overflow: hidden;
  cursor: crosshair;
}

.pdf-canvas {
  display: block;
  width: 100%;
  height: auto;
  background-color: #ffffff;
}

.photo-overlay {
  position: absolute;
  top: 7%;
  left: 72%;
  width: 19%;
  border: 2px solid var(--accent-primary);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9);
  cursor: move;
  touch-action: none;
  user-select: none;
}

.photo-overlay[hidden] {
  display: none !important;
}

.photo-overlay.is-nudge-animating {
  transition: left 90ms ease-out, top 90ms ease-out;
}

.photo-preview {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
}

.resize-handle {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 50%;
  background-color: var(--accent-primary);
  border: 2px solid #ffffff;
  cursor: nwse-resize;
  touch-action: none;
}

/* 6. Nota de privacidad */
.privacy-footer {
  margin-top: 16px;
  text-align: center;
}

.privacy-footer p {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  .btn,
  .file-picker-group,
  .photo-overlay,
  .photo-overlay.is-nudge-animating {
    transition: none !important;
  }
}

/* Adaptación móvil */
@media (max-width: 640px) {
  .app-container {
    padding: 16px;
    border-radius: 10px;
  }

  .app-header h1 {
    font-size: 26px;
  }

  .file-selection {
    grid-template-columns: 1fr;
  }

  .btn {
    min-height: 44px;
  }

  .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .image-controls {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .size-controls {
    width: 100%;
  }

  .size-slider {
    flex: 1;
    width: auto;
    min-width: 0;
    height: 44px;
  }

  .move-controls {
    justify-content: flex-start;
  }

  .action-controls {
    margin-left: 0;
    width: 100%;
  }

  .action-controls .btn {
    flex: 1;
  }

  .preview-panel {
    padding: 12px 8px;
  }

  .resize-handle {
    width: 20px;
    height: 20px;
    right: -9px;
    bottom: -9px;
  }
}
